Home > Blockchain >  Can't find name when using a declared module in angular
Can't find name when using a declared module in angular

Time:09-29

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.

CodePudding user response:

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

  • Related