no-invalid-this
禁止在类或类类对象之外使用
this
关键字.
This is an "extension" rule that replaces a core ESLint rule to work with TypeScript. See Rules > Extension Rules.
The code problem checked by this ESLint rule is automatically checked by the TypeScript compiler. Thus, it is not recommended to turn on this rule in new TypeScript projects. You only need to enable this rule if you prefer the ESLint error messages over the TypeScript compiler error messages.
(Note that technically, TypeScript will only catch this if you have the strict
or noImplicitThis
flags enabled. These are enabled in most TypeScript projects, since they are considered to be best practice.)
This rule extends the base no-invalid-this
rule from ESLint core. 它增加了对 TypeScript 的 this
参数的支持。
¥It adds support for TypeScript's this
parameters.
选项
See eslint/no-invalid-this
's options.
如何使用
- 扁平配置
- 旧版配置
export default tseslint.config({
rules: {
// Note: you must disable the base rule as it can report incorrect errors
"no-invalid-this": "off",
"@typescript-eslint/no-invalid-this": "error"
}
});
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"no-invalid-this": "off",
"@typescript-eslint/no-invalid-this": "error"
}
};
在线运行试试这个规则 ↗