Skip to content

unbound-method ​

A method that uses this, taken off its object without being called or bound: handed to a function (queueMicrotask(this.tick), items.forEach(this.tick)), returned, stored in an object, copied to a binding (const f = ticker.tick) or destructured (const { tick } = ticker). On by default, as an error.

Why: a method reads this from the call, not from where it was declared. ticker.tick() runs it with this set to ticker; const f = ticker.tick; f() runs the same function with this undefined (class bodies are strict mode), and the first this.count throws TypeError: Cannot read properties of undefined. TypeScript accepts every one of these, since the method's type doesn't say it needs its object, so the crash ships. Handed to an event listener, this is the element instead, which fails later and further away.

❌ Rejected: the method runs later, on its own

✕ Rejectedunbound-method
ts
export class Ticker {
  private count = 0;
  tick(): void {
    this.count += 1;
  }
  start(): void {
    queueMicrotask(this.tick);
  }
}

❌ Rejected: copied off the object, then called

✕ Rejectedunbound-method
ts
export class Greeter {
  readonly prefix = "hi";
  greet(name: string): string {
    return `${this.prefix} ${name}`;
  }
}

export function greetAll(names: readonly string[]): readonly string[] {
  const greeter = new Greeter();
  return names.map(greeter.greet);
}
ts
export class Greeter {
  readonly prefix = "hi";
  greet(name: string): string {
    return `${this.prefix} ${name}`;
  }
}

export function greetAll(names: readonly string[]): readonly string[] {
  const greeter = new Greeter();
  { const __la1 = names; const __lf1_0: any = greeter.greet; if (typeof __lf1_0 !== "function") throw new TypeError(`${typeof __lf1_0} is not a function`); const __lr1: any[] = new Array(__la1.length); for (let __li1 = 0, __ln1 = __la1.length; __li1 < __ln1; __li1++) { if (!(__li1 in __la1)) continue; const __le1 = __la1[__li1]!; { __lr1[__li1] = __lf1_0(__le1, __li1, __la1); }} return __lr1; }
}

✅ Accepted: an arrow that calls the method on its object, where it is handed over

✓ Accepted0 diagnostics
ts
export class Ticker {
  private count = 0;
  tick(): void {
    this.count += 1;
  }
  start(): void {
    queueMicrotask(() => this.tick());
  }
}

✅ Also accepted: an arrow-function field, which keeps the this of the instance it was made for

✓ Accepted0 diagnostics
ts
export class Greeter {
  readonly prefix = "hi";
  readonly greet = (name: string): string => `${this.prefix} ${name}`;
}

export function greetAll(names: readonly string[]): readonly string[] {
  const greeter = new Greeter();
  return names.map(greeter.greet);
}
ts
export class Greeter {
  readonly prefix = "hi";
  readonly greet = (name: string): string => `${this.prefix} ${name}`;
}

export function greetAll(names: readonly string[]): readonly string[] {
  const greeter = new Greeter();
  { const __la1 = names; const __lf1_0: any = greeter.greet; if (typeof __lf1_0 !== "function") throw new TypeError(`${typeof __lf1_0} is not a function`); const __lr1: any[] = new Array(__la1.length); for (let __li1 = 0, __ln1 = __la1.length; __li1 < __ln1; __li1++) { if (!(__li1 in __la1)) continue; const __le1 = __la1[__li1]!; { __lr1[__li1] = __lf1_0(__le1, __li1, __la1); }} return __lr1; }
}

✅ Also accepted: bound to its object

✓ Accepted0 diagnostics
ts
export class Ticker {
  private count = 0;
  tick(): void {
    this.count += 1;
  }
  start(): void {
    queueMicrotask(this.tick.bind(this));
  }
}

What counts ​

  • A method of a module-level class (or one it inherits) whose body uses this or super, also inside an arrow in it. Not a method that doesn't, a static one, an arrow-function field, a decorated method (a decorator such as @bound may bind it), or one the constructor sets on the instance (this.tick = this.tick.bind(this), in the method's class or the object's), when it is read through the instance. super.tick reads the prototype's method, which that assignment doesn't change, so it counts.
  • The object is one whose class the checker can see: this, super, new C(), a binding or parameter declared as C, and the receivers the failure rules follow (a field declared with the class, a property of a declared type, a function declared to return the class; see unhandled-failure), in this file or another.
  • Not where the function it is handed to takes the object too: items.forEach(this.tick, this) (also map, filter, some, every, find, findIndex, findLast, findLastIndex, flatMap).
  • Not where the method isn't called: typeof this.tick, this.tick === other, registry.has(this.tick), listeners.delete(this.tick).
  • In JSX, onClick={this.save} on a class component counts the same.

Quick fix ​

Bind it: this.tick.bind(this) (keeps this when it runs), where the object is this, super or a plain name, so reading it a second time is the same object. It changes what the code does on purpose: the call that threw TypeError runs on the object. Where the object is an expression (makeTicker().tick) or a destructuring, there is no fix: write the arrow.

What the rule can't see ​

  • A method of an object whose class isn't written down where the checker looks: a value typed as an interface, a union, or unknown, an element of an array, a value from a package.
  • An object literal's method that uses this (const api = { n: 0, inc() { this.n++ } }).
  • A static method that uses this, taken off its class.
  • A method taken off through a binding that is assigned again (let t = ticker; ...; t = other; queueMicrotask(t.tick)).

Related: unhandled-failure, which follows the same receivers to the methods they call.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra