javascript - 在严格模式的打字稿项目中使用 jsbi
问题描述
我正在开发一个使用 nativeBigInt
的打字稿库。它在 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 并包含一个 .d.ts 文件。这个问题应该得到解决。https://github.com/GoogleChromeLabs/jsbi/pull/67
推荐阅读
- visual-studio-code - 使用 RSA 密钥连接到 VSCode 上的嵌套 SSH
- node.js - 用于 NodeJS 中 App Engine 灵活应用程序的 Google-Cloud Profiler
- error-handling - 为什么 Rust 在使用 '?' 时会在错误类型之间隐式转换?但不是返回值?
- javascript - 根据值对数组元素进行分组并获取其他值的中位数
- distance - 非成对距离测量,同时保留原始 geopandas 数据帧中的所有列
- ffmpeg - 如何更改输入视频的ffmpeg缓冲区
- python - 是否可以在 tkinter 中更新标签?
- php - 如何在ajax和php中传递具有变量值的图像文件
- google-cloud-platform - 在谷歌云中映射流量的最佳方法
- java - 二维数组工作,越界错误,for循环,