【问题标题】:Can't find name when using a declared module in angular在角度中使用声明的模块时找不到名称
【发布时间】:2021-11-20 06:06:17
【问题描述】:

我正在使用 Angular,我想将 scriptJS 添加到我的项目中,以便动态加载一些脚本。

我安装了scriptjs

npm i scriptjs npm install -D @types/scriptjs

现在,类型定义为 this

declare module 'scriptjs'{ 
    var $script: $script; 
    export = $script; 
}

但是当我这样做时

$script('blabla.js', function () {}) 

我收到Can't find name $script 的提示。

我已经在我的项目中添加了其他 @types 包并且它们被正确找到,但是在使用扩展全局范围的包时我仍然很挣扎。

【问题讨论】:

    标签: javascript angular typescript types


    【解决方案1】:

    我设法使用它,但我必须在文件开头导入它才能使用它。
    import * as $script from "scriptjs";

    另外,我看到另一个类似的问题,貌似只能导入你需要的函数https://stackoverflow.com/a/53026833/14079026

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2021-11-06
    • 2016-10-12
    • 1970-01-01
    • 2015-12-30
    • 2020-10-22
    • 2022-01-07
    • 2022-01-21
    • 2018-05-15
    相关资源
    最近更新 更多