TS2420Semantic Error
Since TS 1.0

Fix TS2420: Class Incorrectly Implements Interface

Learn why TypeScript throws TS2420 when a class does not satisfy the interface it implements, and how to fix missing, private and optional members.

error TS2420: Class 'X' incorrectly implements interface 'Y'

What This Error Means

TS2420 means a class promised more than it delivered. The implements clause is a contract: it tells the compiler, and every reader of your code, that instances of this class can be used anywhere the interface is expected. When the class type turns out not to be assignable to the interface, TypeScript rejects the clause and points at the class name.

The check is plain structural assignability, run once over the whole class. TypeScript takes the instance type the class produces and asks whether it fits the interface. A member can fail that question in several ways: it can be absent, it can be present but private or protected where the interface declares it public, or it can be optional where the interface requires it. No compiler flag turns this check on or off — it is part of the core checker and fires under any configuration.

The headline is only half the message. The indented line beneath it is the part that tells you what to do:

// The general shape of the error:
// Class 'OrdersPage' incorrectly implements interface 'OnInit'.
//       ~~~~~~~~~~                                   ~~~~~~
//       your class                                   the contract
//   Property 'ngOnInit' is missing in type 'OrdersPage' but required in type 'OnInit'.
//             ~~~~~~~~
//             the member that actually broke it

Common Causes

1. A Required Member Was Never Written

By far the most common case, and the one almost every Angular developer meets first. The implements clause is added from a snippet or an import, and the lifecycle method it exists for is never typed out.

// ❌ Broken
interface OnInit {
  ngOnInit(): void
}
 
export class OrdersPage implements OnInit {
  //         ~~~~~~~~~~ Error: Class 'OrdersPage' incorrectly implements interface 'OnInit'.
  //                    Property 'ngOnInit' is missing in type 'OrdersPage' but required in type 'OnInit'.
  orders: Order[] = []
}
// ✅ Fixed — implement the member the interface declares
export class OrdersPage implements OnInit {
  orders: Order[] = []
 
  ngOnInit(): void {
    this.loadOrders()
  }
 
  loadOrders(): void {
    this.orders = []
  }
}

Note that implements does nothing at runtime. It creates no method and provides no default — it only asks the compiler to check. Removing the clause silences TS2420 and also removes the only guarantee you had.

2. The Class Made a Public Member Private or Protected

An interface describes a public surface. If the class hides a member behind private or protected, callers holding the interface type could not reach it, so the class no longer satisfies the contract.

// ❌ Broken
interface UserRepository {
  count: number
  find(id: string): Promise<User | undefined>
}
 
class InMemoryUserRepository implements UserRepository {
  //  ~~~~~~~~~~~~~~~~~~~~~~ Error: Class 'InMemoryUserRepository' incorrectly implements
  //     interface 'UserRepository'. Property 'count' is private in type
  //     'InMemoryUserRepository' but not in type 'UserRepository'.
  private count = 0
  private users = new Map<string, User>()
 
  async find(id: string): Promise<User | undefined> {
    this.count++
    return this.users.get(id)
  }
}
// ✅ Fixed — the interface describes the public API, so drop the internal counter from it
interface UserRepository {
  find(id: string): Promise<User | undefined>
}
 
class InMemoryUserRepository implements UserRepository {
  private count = 0
  private users = new Map<string, User>()
 
  async find(id: string): Promise<User | undefined> {
    this.count++
    return this.users.get(id)
  }
}

Decide which side is wrong before you edit: if consumers genuinely read count, make the class member public; if it is bookkeeping, it never belonged in the interface.

3. A Dependency Upgrade Added a Member to the Interface

The class compiled yesterday and fails today after npm update. Nothing in your code changed — the interface grew. Angular's ControlValueAccessor is the classic example: setDisabledState arrived after the other three members.

// ❌ Broken — after the upgrade (interface shortened to two of its four members)
interface ControlValueAccessor {
  writeValue(value: unknown): void
  setDisabledState(isDisabled: boolean): void // added by the newer version
}
 
class CurrencyInput implements ControlValueAccessor {
  //  ~~~~~~~~~~~~~ Error: Property 'setDisabledState' is missing in type 'CurrencyInput'
  //                but required in type 'ControlValueAccessor'.
  private value: unknown = null
 
  writeValue(value: unknown): void {
    this.value = value
  }
}
// ✅ Fixed — adopt the new member
class CurrencyInput implements ControlValueAccessor {
  private value: unknown = null
  private disabled = false
 
  writeValue(value: unknown): void {
    this.value = value
  }
 
  setDisabledState(isDisabled: boolean): void {
    this.disabled = isDisabled
  }
}

4. The Member Is Optional on the Class but Required by the Interface

A base class offers a hook as optional, a subclass inherits it, and the interface demands it unconditionally. Because the subclass never declares the member itself, the mismatch surfaces at the class level as TS2420 rather than against a declaration.

// ❌ Broken
interface RowSelection {
  selectedIds: string[]
  onSelect(id: string): void
}
 
abstract class TableBase {
  onSelect?(id: string): void
}
 
class DataTable extends TableBase implements RowSelection {
  //  ~~~~~~~~~ Error: Class 'DataTable' incorrectly implements interface 'RowSelection'.
  //            Types of property 'onSelect' are incompatible.
  //            Type '((id: string) => void) | undefined' is not assignable to
  //            type '(id: string) => void'.
  selectedIds: string[] = []
}
// ✅ Fixed — declare the member on the class that claims the interface
class DataTable extends TableBase implements RowSelection {
  selectedIds: string[] = []
 
  onSelect(id: string): void {
    this.selectedIds = [...this.selectedIds, id]
  }
}

The other direction works too: if the hook really is optional for every consumer, mark it onSelect?(id: string): void in RowSelection and let callers check before invoking it.

How to Fix It

  1. Read the indented line, not the headline. "Class X incorrectly implements interface Y" never tells you anything you did not already know. The line underneath names the member and the exact failure — missing, private, or incompatible — and that is the whole diagnosis.

  2. Add the member the compiler names. Most TS2420s are a one-method fix. Your editor's "Implement interface" quick fix will stub every missing member at once; check what it generated before you accept it, because it stubs optional members too and can bury the one method you actually meant to write.

  3. Match the visibility. If the message says a property is private or protected in your class "but not" in the interface, either make the class member public or remove it from the interface. Keep interfaces to the surface consumers use — internal state belongs on the class alone.

  4. If the message names a signature mismatch, you are looking at TS2416. A member that exists but has the wrong parameter or return type is reported against that member, not against the class. Fix the signature there and TS2420 goes away with it.

  5. Do not delete the implements clause and do not cast the class to the interface. Both make the error disappear without making the class usable where the interface is expected, and the failure moves to the first caller that relies on the contract at runtime. If you need a deliberate partial implementation, mark the class abstract instead — abstract classes are allowed to leave interface members undeclared for subclasses to fill in.

FAQ

What causes TypeScript error TS2420?

TS2420 fires when a class says it implements an interface but its instance type is not assignable to that interface. The usual reasons are a member that was never written, a member the class marked private or protected while the interface declares it public, and a member that is optional on the class but required by the interface. The indented line under the error names the member that broke the check.

The check is structural and runs over the whole class, which is why the squiggle sits on the class name rather than on any particular line inside the body. TypeScript is not objecting to a statement — it is objecting to the shape the class produces.

How do I fix Class incorrectly implements interface 'OnInit' in Angular?

Add the lifecycle method the interface requires. OnInit declares a single member, ngOnInit, so a component that lists implements OnInit must define ngOnInit as a public method:

export class OrdersPage implements OnInit {
  ngOnInit(): void {
    this.loadOrders()
  }
}

The same pattern covers the rest of the family: OnDestroy needs ngOnDestroy, OnChanges needs ngOnChanges, and ControlValueAccessor needs all four of writeValue, registerOnChange, registerOnTouched and setDisabledState. If the error appeared straight after an Angular upgrade, the interface gained a member — implement it rather than dropping the clause, because Angular calls these methods by name whether or not the class claims the interface.

Why does TypeScript report TS2416 instead of TS2420 for a wrong method signature?

TS2420 is the whole-class check; TS2416 is the per-member one. When the class actually declares the member and only its type is wrong, the compiler can point at that declaration, so it reports the narrower error there instead:

interface ToolbarButton {
  label: string
  icon: string
}
 
class SaveButton implements ToolbarButton {
  label = "Save"
  icon?: string // declared here, so the compiler blames the declaration
  // ~~~~ TS2416: Property 'icon' in type 'SaveButton' is not assignable to the same
  //      property in base type 'ToolbarButton'.
}

Compare that with cause 4 above, where the optional member is inherited rather than declared: with no declaration to blame, the same mismatch comes back as TS2420 on the class. Either way the remedy is identical — make the member fit the contract. Fix the signature and both errors disappear together.

Related Errors

Practice This

Browse all TypeScript practice challenges to keep sharpening your type-level skills.

Related Concepts

Share this reference

Become a TypeScript Pro

Track your progress through 200+ hands-on challenges. Free, sign in with GitHub.

Or start solving right away: explore all TypeScript challenges