0

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.

Bobby
  • 4,372
  • 8
  • 47
  • 103

1 Answers1

1

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

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 28 '21 at 08:08