-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
Repro
{
"rules": {
"@typescript-eslint/unbound-method": [
"error",
{
"ignoreStatic": true
}
]
}
}
class SomeClass {
functionProperty = function(this: any) { console.log(`this is ${this}`); };
}
const myFunctionProperty = new SomeClass().functionProperty; // X - Missing eslint error
myFunctionProperty(); // Doesn't work, despite no eslint error
Expected Result
unbound-method
error when initializing myfunctionProperty
Actual Result
No error, but calling myFunctionProperty()
prints out this is undefined
Additional Info
I wonder if there should also be a rule for requiring the this
parameter in inline function definitions be declared to have the most specific type possible(?). If I declare functionProperty = function(this: SomeClass) { ... }
then there's a compiler error when I try to call myFunctionProperty()
:
The 'this' context of type 'void' is not assignable to method's 'this' of type 'MyClass'.ts(2684)
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
2.17.0 |
@typescript-eslint/parser |
2.17.0 |
TypeScript |
3.7.5 |
ESLint |
6.8.0 |
node |
10.19.0 |
npm |
6.13.4 |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin