如何使用摩卡修复 TypeScript 项目中"Property 'should' does not exist on type 'string'"错误?



在我正在处理的一个使用 TypeScript 的 NodeJS 项目中,有一些 .ts 文件其中包含使用 mocha 的测试。我已经将一个测试文件从javascript移植到TypeScript,我在几行上得到了这些错误:

Property 'should' does not exist on type 'number'.
Property 'should' does not exist on type 'boolean'.
Property 'should' does not exist on type 'string'.

以前在其他一些存储库中看到过这个,我记得修复了它,但现在我根本不记得我做了什么!

更改

require('should');

import * as should from 'should';

因为我正在将此文件从原版JS移植到TypeScript,所以我只更改了一些require语句,但不是每个语句。记得把它们全部改掉!

相关内容

最新更新