[英]Can't find name when using a declared module in angular
I am using Angular and I would like to add scriptJS to my project in order to load some script dynamically.我正在使用 Angular 并且我想将 scriptJS 添加到我的项目中以便动态加载一些脚本。
I installed scriptjs我安装了脚本
npm i scriptjs
npm install -D @types/scriptjs
npm i scriptjs
npm install -D @types/scriptjs
Now, the types are defined like this现在,类型定义如下
declare module 'scriptjs'{
var $script: $script;
export = $script;
}
but when I do但是当我这样做的时候
$script('blabla.js', function () {})
I am prompted with Can't find name $script
.我收到提示
Can't find name $script
。
I already added other @types package to my project and they are correctly found, but I still struggle when using package that extend the global scope.我已经在我的项目中添加了其他@types package,并且可以正确找到它们,但是在使用扩展全局 scope 的 package 时,我仍然很挣扎。
I managed to use it, but I had to import it at the beginning of the file before using it.我设法使用它,但在使用它之前我必须在文件的开头导入它。
import * as $script from "scriptjs";
Also, I saw another similar question, and it looks like you can import only the function you need https://stackoverflow.com/a/53026833/14079026另外,我看到了另一个类似的问题,看起来你只能导入你需要的function https://stackoverflow.com/a/53026833/14079026
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.