带有TypeScript的Mocha:参数'id'隐式具有'any'类型? [英] Mocha with TypeScript: Parameter 'id' implicitly has an 'any' type?
本文介绍了带有TypeScript的Mocha:参数'id'隐式具有'any'类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个简单的函数,如下所示:
I wrote a simple function as follows:
export const courseIndustry: any = {
getById: (id: string) => {
return {};
}
};
我以为我指定参数id为字符串类型,但mocha test
声明:
And I thought I specified that the argument id is of type string, but the mocha test
claims:
mocha -r ts-node/register -r espower-typescript/guess test/**/*.test.ts
Unable to compile TypeScript: courseIndustry.ts(4, 15): error TS7006: Parameter 'id' implicitly has an 'any' type.
我在哪里错了?
推荐答案
该错误似乎由espower-typescript/guess引发.因此,我检查了其文档,发现以下开关可以解决以下错误:"TS_NODE_TRANSPILE_ONLY = 1".
The error seems thrown by espower-typescript/guess. So I checked its document and find the following switch can work around the errors: 'TS_NODE_TRANSPILE_ONLY=1'.
因此,shell命令的最终版本使其可以工作:
So the final version of the shell command make it work:
TS_NODE_TRANSPILE_ONLY=1 mocha -r ts-node/register --require espower-typescript/guess test/**/*.test.ts --exit
这篇关于带有TypeScript的Mocha:参数'id'隐式具有'any'类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文