虽然我能找到的每个主题都想要修复或禁用 TS2339 错误,但我正在尝试使 eslint 规则与 typescript 规则同步,并且我想启用它。
在查看 typescript-eslint 项目时,我似乎找不到如何启用 TS2339 规则或找到关联的名称。
您可以看到我正在尝试执行的设置:Typescript PlayGround
type Person = {
name: string;
}
const me: Person = {
name: 'Kenny'
}
// this should error both in the IDE (which it does) and with eslint command line with the @typescript-eslint configuration (which it does NOT)
me.age = 3
按照此处找到的设置和配置:规则设置
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./tsconfig.json'],
},
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
};
Eslint 和 Typescript 在这里是分开的。运行 Typescript compiler 时,您将收到 TS2339 错误,如
tsc --noEmit
Eslint 关注其他类别的错误,并且它会留下无法编译到编译器本身的报告打字稿。
在编辑器中,您会同时看到 eslint linter 和 typescript 编译器支持的结果叠加在您的代码上,并且您将 TS 错误与您期望从 eslint 获得的内容混淆了,但您不会。