相关疑难解决方法(0)

TypeScript:在单元测试中找不到模块的声明文件,只有

我在 Windows 10 上使用带有 Visual Studio Code 的 TypeScript 来开发 NPM 模块。我将 mocha/chai 与 nyc (istanbul) 结合使用进行单元测试和代码覆盖。

对于我的一些测试,我想使用 chai-bytes 更容易地比较缓冲区。不幸的是,chai-bytes 模块中没有类型定义文件,@types/chai-bytes 中也没有可用的定义。

因此,我为 chai-bytes 插件编写了自己的类型定义文件(非常简单),但在执行过程中npm test出现以下错误:

TSError: ? Unable to compile TypeScript:
test/utls/BitArray-test.ts(3,23): error TS7016: Could not find a declaration file for module 'chai-bytes'. 'C:/Users/<user>/Source/Repos/velux-api/node_modules/chai-bytes/index.js' implicitly has an 'any' type.
  Try `npm install @types/chai-bytes` if it exists or add a new declaration (.d.ts) file containing `declare module 'chai-bytes';`
test/utls/BitArray-test.ts(48,38): error TS2339: Property 'equalBytes' does not exist on type …
Run Code Online (Sandbox Code Playgroud)

mocha.js node.js chai typescript nyc

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

chai ×1

mocha.js ×1

node.js ×1

nyc ×1

typescript ×1