简体   繁体   中英

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.

I installed 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 .

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM