Typescript: Use @types for jsrsasign without import

Viewed 338

I'm developing a typescript application (chrome extension) and want to use @types for a downloaded library jsrsasign-all-min.js from https://github.com/kjur/jsrsasign. Therefore I've installed:

npm install --save @types/jsrsasign.

Now the only way to get it working in .ts file is:

(window as any).KJUR.jws.JWS.readSafeJSONString((window as any).b64utoutf8(token))

IDE allows me to do imports:

import { b64utoutf8, KJUR } from "jsrsasign";
KJUR.jws.JWS.readSafeJSONString(b64utoutf8(token))

but this will throw a runtime error:

Uncaught SyntaxError: Cannot use import statement outside a module

I also can do this without import:

jsrsasign.KJUR.jws.JWS.readSafeJSONString(jsrsasign.b64utoutf8(token))

but this will also result in runtime error:

Error handling response: ReferenceError: jsrsasign is not defined

Question: is there a way to get it working in .ts files with type control?

My tsconfig.json:

{
  "compilerOptions": {
    "outDir": "extension",
    "target": "es6",
    "removeComments": true,
  },
  "include": [
    "**.ts"
  ]
}
0 Answers
Related