[英]Typescript error : Function declarations are not permitted in blocks in strict mode
[英]Using jsbi in a typescript project with strict mode
我正在使用本机BigInt
的 typescript 库。 它在 chrome 中效果很好,但在 Safari 中效果不佳。 所以我遇到了解决这个问题的jsbi
“polyfill”。
但由于某种原因,我无法正确导入库。
我首先尝试像这样导入它:
import JSBI from 'jsbi'
类型是正确的,但是在运行时JSBI
是未定义的,我不能在它上面调用任何方法。 (例如TypeError: Cannot read property 'subtract' of undefined
)
所以我试着做:
import * as JSBI from 'jsbi'
但后来它甚至无法编译,我得到了各种错误,比如Cannot use namespace 'JSBI' as a type.
. 我也尝试访问像这样的方法JSBI.JSBI.subtract
,但后来我得到错误Property 'JSBI' does not exist on type 'typeof import("/project/node_modules/jsbi/jsbi")'.
我让它工作的唯一方法是使用以下导入:
import * as JSBI from 'jsbi/dist/jsbi-umd.js'
这实际上奏效了。 JSBI 是在运行时定义的,我可以访问它的方法。 但是,它仅在禁用严格模式时才有效。 当我启用它时,我得到了错误
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';`
我试图将自己的.d.ts 模块声明为临时修复,但它也不起作用。
我在这里错过了什么吗?
JSBI 已迁移到 Typescript 并包含 adts 文件。 这个问题应该得到解决。 https://github.com/GoogleChromeLabs/jsbi/pull/67
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.