Disallow use of this in contexts where the value of this is undefined.
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-invalid-this": "error"
}
} // Add "use strict" to the .ts file.
function baz(arg0: () => object) {
return arg0;
}
export class Bar {
public a: number;
public constructor() {
this.a = 0;
baz(() => this);
}
} // Add "use strict" to the .ts file.
function baz(arg0: () => object) {
return arg0;
}
export function foo1() {
this.a = 0;
baz(() => this);
}
export const foo2 = () => {
this.a = 0;
baz(() => this);
}; plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.