[unbound-method] Should prevent conforming to a bound-style interface method with an unbound method

Author: jtbandesCreated Jun 8, 2021Updated Sep 16, 2026
Labelspackage: eslint-pluginenhancement: plugin rule optionaccepting prs
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

typescript
interface Foo {
  unbound(): number;
  unboundOk(this: void): number;
  bound: () => number;
}

function what(f: Foo) {
  const unbound = f.unbound;      // lint error 
  const unboundOk = f.unboundOk;  // no error 
  const bound = f.bound;          // no error 

  // console.log(unbound());  // runtime error (expected)
  console.log(unboundOk()); // runtime error ❌
  console.log(bound());     // runtime error ❌
}

class Example implements Foo {
  x = 3;
  unbound() { return this.x; }
  unboundOk() { return this.x; }   // no error  (TypeScript issue rather than typescript-eslint issue?)
  bound() { return this.x; }      // no error  (this issue)
}
what(new Example());

eslint config: https://github.com/foxglove/eslint-plugin/blob/main/configs/typescript.js tsconfig: https://github.com/foxglove/studio/blob/main/packages/tsconfig/tsconfig.base.json

Expected Result

class Example implements Foo is problematic. There should be an error on bound() { return this.x } when is used to satisfy the interface requirement bound: () => number;.

Actual Result

The lint rule does not reject this incorrect method implementation, which leads to a runtime error.

Versions

package version
@typescript-eslint/eslint-plugin 4.26.0
@typescript-eslint/parser 4.26.0
TypeScript 4.3.2
ESLint 7.27.0
node 15.9.0

Source: typescript-eslint/typescript-eslint