Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท Error Codes Worth Knowing

TypeScript error TS2416: property not assignable to base type

TS2416 means a class member does not match the same member in its base class or interface. See what triggers it, how to read the nested message, and how to fix it.

TS2416 reads Property 'speak' in type 'Dog' is not assignable to the same property in base type 'Animal'. A class that extends another class (or implements an interface) must keep each member compatible with the original: wherever an Animal is expected, a Dog must work. If the subclass changes a method's parameters or return type so that this is no longer true, the compiler rejects it and prints the exact difference on the indented lines below.

The first line names the member and the two types. The nested lines are the real explanation, so read them from the bottom up: the last line is the smallest mismatch.

TypeScript
class Animal { speak(times: number): string { return ""; } }
class Dog extends Animal {
  speak(times: string): string { return times; }  // error TS2416
}

Try it

TypeScript A method that breaks the contract

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Compatible overrides

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

The rule behind the error is substitutability:

Part of the member What a subclass may do
Return type Return the same type or a subtype (narrower).
Parameter types Accept the same or a supertype (wider). Narrower parameters are rejected for properties holding functions; method shorthand is checked bivariantly in some cases.
Property type Same type or a subtype. A property cannot become wider.
Optionality A required base property cannot become optional.
Modifiers private, protected and readonly mismatches are also reported.

Usage notes

  • Where it appears: extends always, and implements when a member exists but its type is wrong (a missing member is TS2420 instead).
  • Methods versus function properties. With strictFunctionTypes, function-typed properties are checked strictly, while methods declared with method syntax are compared more loosely for historical reasons. Do not rely on that looseness; keep overrides compatible.
  • Use override. The keyword makes the intent explicit and, with noImplicitOverride, catches misspelt method names.
  • Fix choices: change the subclass to match, change the base type to be general enough, or reconsider inheritance. If a Dog really cannot do what an Animal does, it probably should not extend it.
  • Generic base classes produce the same message with substituted types, such as Box<string>.