I have been developing a TypeScript library that relies on native BigInt
s. While it functions perfectly in Chrome, I encountered some issues with Safari. After some research, I stumbled upon the jsbi
"polyfill" that seems to solve this problem.
Unfortunately, importing the library has proven to be quite challenging for me.
Initially, I attempted to import it in the following manner:
import JSBI from 'jsbi'
Although the types were correct, at runtime the variable JSBI
would be undefined and I was unable to utilize any of its methods. This resulted in errors like
TypeError: Cannot read property 'subtract' of undefined
.
Subsequently, I tried a different approach:
import * as JSBI from 'jsbi'
However, this led to compilation errors such as
Cannot use namespace 'JSBI' as a type.
. When attempting to access methods using JSBI.JSBI.subtract
, another error surfaced - Property 'JSBI' does not exist on type 'typeof import("/project/node_modules/jsbi/jsbi")'.
Ultimately, the only successful import method I found was:
import * as JSBI from 'jsbi/dist/jsbi-umd.js'
This approach worked well, allowing me to access JSBI's methods at runtime. However, this solution only functions properly when strict mode is disabled. Enabling strict mode resulted in 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 even attempted to create my own .d.ts module as a temporary workaround, but unfortunately, this did not resolve the issue either.
Am I overlooking something crucial here?