- Error
- Reported by the type checker
TS2416
Property '{0}' in type '{1}' is not assignable to the same property in base type '{2}'.
A subclass or implementing class redeclares a property or method with a type the base type doesn't allow. Make it compatible with the base member.
What it means
When a class overrides a property or method from its base class or an implemented interface, the new member's type must be assignable to the base member's type, so code that only knows the base type still works.
Example
class Shape {
area(): number {
return 0;
}
}
export class Square extends Shape {
area(): string {
return "4";
}
}
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(7,3): error TS2416: Property 'area' in type 'Square' is not assignable to the same property in base type 'Shape'.
Type '() => string' is not assignable to type '() => number'.
Type 'string' is not assignable to type 'number'.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Change the overriding member to a compatible type (here return a
number). - If it's really a different operation, give it a different name.