I'm working on a typescript library that is using native BigInt
s. It works great in chrome, but not in Safari. So I came across the jsbi
"polyfill" that takes care of this.
But for some reason, I can't import the library correctly.
I first tried to import it like this:
import JSBI from 'jsbi'
The types are correct, but at runtime JSBI
is undefined and I cannot call any methods on it. (eg. TypeError: Cannot read property 'subtract' of undefined
)
So I tried doing:
import * as JSBI from 'jsbi'
But then it wouldn't even compile, I get various errors like Cannot use namespace 'JSBI' as a type.
. I also tried to access the methods like this JSBI.JSBI.subtract
, but then I get the error Property 'JSBI' does not exist on type 'typeof import("/project/node_modules/jsbi/jsbi")'.
The only way I got it working was by using the following import:
import * as JSBI from 'jsbi/dist/jsbi-umd.js'
This actually worked. JSBI is defined at runtime and I can access its methods. However, it only works when strict mode is disabled. When I enable it, i get the error
error TS7016: Could not find a declaration file for module 'jsbi/dist/jsbi-umd.js'.
'/project/node_modules/jsbi/dist/jsbi-umd.js' implicitly has an 'any' type.
Try `npm install @types/jsbi` if it exists or add a new declaration (.d.ts) file containing `declare module 'jsbi/dist/jsbi-umd.js';`
I event tried to declare my own.d.ts module as a temporary fix, but it didn't work work either.
Am I missing something here?
JSBI has been migrated to Typescript and includes adts file. This problem should be resolved. https://github.com/GoogleChromeLabs/jsbi/pull/67
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.