无隐式任何规则(&Q;) [英] Eslint Typescript "No Implicit Any" rule
本文介绍了无隐式任何规则(&Q;)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在与eslint一起设置一个新的打字项目。我正在尝试正确设置eslint规则,以便tsc
命令运行时不会出错。我在tsconfig.json
中使用的&noImplitAny";规则有问题,但我无法在eslint中检查这一点。
.eslintrc.js:
module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json"],
sourceType: "module",
},
rules: {
"no-undef": "warn",
},
plugins: ["@typescript-eslint"],
settings: {
"import/resolver": {
node: {
extensions: [".js", ".ts"],
},
},
},
};
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "ES6",
"declaration": true,
"outDir": "./lib",
"strict": true,
"noImplicitAny": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "**/__tests__/*"]
}
简而言之,我希望eslint检查隐含的any并警告其用法。如何配置.eslintrc.js
中的规则以实现此目的?
推荐答案
在TypeScrip-ESLint中实现了许多no-unsafe-*
规则:
no-unsafe-call
-禁止调用类型为any
的表达式
no-unsafe-member-access
-禁止将any
用作成员名称no-unsafe-argument
-禁止将any
作为函数参数传递no-unsafe-assignment
-禁止在作业中使用any
extends: [
'plugin:@typescript-eslint/recommended-requiring-type-checking',
在类似的注释中,有no-explicit-any
。将所有这些放在一起,您应该可以完全避免any
问题。
这篇关于无隐式任何规则(&Q;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文