在Ts项目中禁用使用’any’类型吗?

huangapple go评论61阅读模式
英文:

Disable use of 'any' in Ts project?

问题

这是我的当前 tsconfig.json 文件:

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "strict": true,
    "strictNullChecks": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitAny": true,
    "allowUnreachableCode": false,
    "strictFunctionTypes": true
  }
}
英文:

Making a React Native app with expo/typescript and since I'm working in a team I want to disable use of type:any since it happened a couple of times someone puts it and forgets to remove it and it doesn't end well usually

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "strict": true,
    "strictNullChecks": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitAny": true,
    "allowUnreachableCode": false,
    "strictFunctionTypes": true,
  },
}

This is my current tsconfig.json


</details>


# 答案1
**得分**: 2

你需要使用`typescript-eslint`中的[`no-explicit-any`][1]

基本的TypeScript设置中没有这个选项。

[1]: https://typescript-eslint.io/rules/no-explicit-any/

<details>
<summary>英文:</summary>

You&#39;ll need the [`no-explicit-any`][1] from `typescript-eslint` ! 

The basic ts setting doesn&#39;t have that option. 


  [1]: https://typescript-eslint.io/rules/no-explicit-any/

</details>



# 答案2
**得分**: 1

TypeScript本身没有这个设置,但[`typescript-eslint`][1]有一个:[`no-explicit-any`](https://typescript-eslint.io/rules/no-explicit-any)。

  [1]: https://typescript-eslint.io

<details>
<summary>英文:</summary>

TypeScript itself doesn&#39;t have a setting for that, but [`typescript-eslint`][1] has one: [`no-explicit-any`](https://typescript-eslint.io/rules/no-explicit-any).


  [1]: https://typescript-eslint.io

</details>



huangapple
  • 本文由 发表于 2023年4月17日 15:37:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032713.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定