摩卡与打字稿:参数 'id'隐含地有一个 'any'类型? [英] Mocha with TypeScript: Parameter 'id' implicitly has an 'any' type?

查看:68
本文介绍了摩卡与打字稿:参数 '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

这篇关于摩卡与打字稿:参数 'id'隐含地有一个 'any'类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆