TS2420
TypeScriptERRORCriticalClassesHIGH confidence

Class incorrectly extends base class

What this means

A derived class incorrectly extends a base class, often because of incompatible property types or access modifiers.

Why it happens
  1. 1A property in the derived class has a type that is not assignable to the same property in the base class.
  2. 2Overriding a public property with a private one.
  3. 3The constructor of the derived class does not correctly call 'super()' when required.
How to reproduce

A subclass overrides a property with an incompatible type.

trigger — this will error
trigger — this will error
class Animal {
  name: string;
}
class Dog extends Animal {
  name: number; // Incompatible type
}

expected output

error TS2415: Class 'Dog' incorrectly extends base class 'Animal'.
  Types of property 'name' are incompatible.
    Type 'number' is not assignable to type 'string'.

Fix 1

Ensure property types are compatible

WHEN Property types conflict.

Ensure property types are compatible
class Animal {
  name: string;
}
class Dog extends Animal {
  name: string; // Correct type
}

Why this works

The subclass property type must be assignable to the base class property type.

Fix 2

Use a different property name in the subclass

WHEN The subclass property is unrelated to the base class property.

Use a different property name in the subclass
class Animal {
  name: string;
}
class Dog extends Animal {
  dogTagId: number;
}

Why this works

Avoiding a name collision prevents the type conflict.

What not to do

✕ Use 'any' as the type in the subclass

This defeats the purpose of type checking and can hide significant bugs in your class hierarchy.

Sources
Official documentation ↗

microsoft/TypeScript src/compiler/diagnosticMessages.json

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All TypeScript errors