带有 TypeScript 的 Mocha:参数 'id' 隐式具有 'any' 类型?

Mocha with TypeScript: Parameter 'id' implicitly has an 'any' type?

我写了一个简单的函数如下:

export const courseIndustry: any = {
  getById: (id: string) => {
    return {};
  }
};

我以为我指定了参数 id 是字符串类型,但是 mocha test 声称:

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.

我哪里错了?

尝试使用另一个转译器,如 typescript-compiler 或任何其他转译器并尝试编译。

enter link description here

错误似乎是由 espower-typescript/guess 抛出的。所以我检查了它的文档,发现以下开关可以解决错误:'TS_NODE_TRANSPILE_ONLY=1'.

因此 shell 命令的最终版本使其生效:

TS_NODE_TRANSPILE_ONLY=1 mocha -r ts-node/register --require espower-typescript/guess test/**/*.test.ts --exit