fix(eslint-plugin): [unbound-method] respect `this: void` on class pr… · typescript-eslint/typescript-eslint@7fce912 · GitHub
Skip to content

Commit 7fce912

Browse files
fix(eslint-plugin): [unbound-method] respect this: void on class properties
A class property initialized with a function expression was the only literal-function case that skipped `checkMethod`, so its own `this: void` annotation was ignored: ```ts const Foo = { floor: function (this: void) {} }; const { floor } = Foo; // correctly not reported class Foo { floor = function (this: void) {} } const { floor } = new Foo(); // reported, despite `this: void` ``` Routing it through `checkMethod` fixes that, and makes the two property cases identical enough to share a branch. `ts.isFunctionExpression` narrows the initializer for real, so the cast the old `.kind` check needed goes away. Skipping `checkMethod` also meant `firstParamIsThis` went uncomputed, so these reports never carried the message that suggests annotating with `this: void`. They do now, which moves 19 expectations - and leaves the plain `unbound` message covered only by a new case whose function expression annotates a non-`void` `this`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 7a8dc4d commit 7fce912

2 files changed

Lines changed: 48 additions & 31 deletions

File tree

‎packages/eslint-plugin/src/rules/unbound-method.ts‎

Lines changed: 7 additions & 13 deletions

‎packages/eslint-plugin/tests/rules/unbound-method.test.ts‎

Lines changed: 41 additions & 18 deletions

0 commit comments

Comments
 (0)