我在 TS 2.8 中导入 TextEncoding 时遇到了很大的麻烦。我是从 npm 安装的,并尝试导入我们如下:
import { TextDecoder } from 'text-encoding';
或者
import { } from 'text-encoding';
但是,无论我是否尝试在代码中实现 TextDecoder,尝试在 VS 中构建时都会收到以下错误。
node_modules/@types/text-encoding/index.d.ts(25,40): error TS2304: Cannot find name 'TextDecoderOptions'.
node_modules/@types/text-encoding/index.d.ts(25,61): error TS2304: Cannot find name 'TextDecoder'.
有什么建议吗?
最佳答案
我有一个解决方案,但这取决于我使用一些带 Angular npm 包...
适用于https://www.npmjs.com/package/text-encoding-polyfill中所有浏览器的polyfill
npm i text-encoding-polyfill
以及与https://www.npmjs.com/package/@types/text-encoding中的TS兼容的类型
npm i @types/text-encoding
最后使用此导入进入 Angular 应用程序
import { TextEncoder } from 'text-encoding-polyfill';
稍后您可以使用letencoder = new TextEnconder()
我希望这可以帮助你,它解决了我的问题
关于angular - 在 TS 2.8 中使用 TextEncoding 和 Angular 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51885136/