noFallthroughCasesInSwitch
我已在 tsconfig.json 文件中启用该选项。function getRandomInt(max: number) {
return Math.floor(Math.random() * max);
}
switch(getRandomInt(3)) {
/* falls through */
/* fall through */
/* FALLTHROUGH */
case 1: /* falls through */ /* fall through */ /* FALLTHROUGH */ /* <----- Still getting an error here "Fallthrough case in switch. (7029)" */
/* falls through */
/* fall through */
/* FALLTHROUGH */
console.log(1);
/* falls through */
/* fall through */
/* FALLTHROUGH …
Run Code Online (Sandbox Code Playgroud) 我有一个基本泛型类:
abstract class BaseClass<T> {
abstract itemArray: Array<T>;
static getName(): string {
throw new Error(`BaseClass - 'getName' was not overridden!`);
}
internalLogic() {}
}
Run Code Online (Sandbox Code Playgroud)
和继承人:
type Item1 = {
name: string
}
class Child1 extends BaseClass<Item1> {
itemArray: Array<Item1> = [];
static getName(): string {
return "Child1";
}
}
type Item2 = {
name: number
}
class Child2 extends BaseClass<Item2> {
itemArray: Array<Item2> = [];
static getName(): string {
return "Child2";
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想要定义一个以继承者作为其值的对象:
type IChildrenObj = {
[key: string]: …
Run Code Online (Sandbox Code Playgroud) 使用启动了一个react/typescript项目react-scripts
,添加了一个.eslintrc.json
包含以下内容的文件:
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"react-app",
"react-app/jest"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint"
],
"rules": {
"import/no-anonymous-default-export": "off",
"no-explicit-any": "error",
"@typescript-eslint/no-extra-semi": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-empty-interface": "off"
}
}
Run Code Online (Sandbox Code Playgroud)
现在,由于某种我不知道的原因,每个文件都以 warning/error: 开头Line 1:1: Definition for rule 'no-explicit-any' was not found no-explicit-any
,即使文件甚至没有类型any
,即使文件是空的! …