no-invalid-this
Disallow
this
keywords outside of classes or class-like objects.
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.)
此规则扩展了基本 eslint/no-invalid-this
规则。
它增加了对 TypeScript 的 this
参数的支持。
英:This rule extends the base eslint/no-invalid-this
rule.
It adds support for TypeScript's this
parameters.
如何使用
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"
}
};
选项
资源
摘自 ❤️ ESLint 内核