Overriding Interface Properties

What

Property overriding allows you to redefine a property from a base interface with a more specific type in a child interface.

How

The new type must be compatible with (a subtype of) the original type. You cannot change a property to a completely unrelated type:

interface Character {
  rank: string | number;
}

// Valid: 'number' is compatible with 'string | number'
interface Warrior extends Character {
  rank: number;
}

// Error: 'boolean' is NOT compatible with 'string | number'
interface Mage extends Character {
  rank: boolean;
}

Why

Overriding is useful for narrowing down broad types to more specific ones as you move down a type hierarchy. For example, a generic “Event” might have a broad payload type, while a specific “SystemErrorEvent” would override it to be a specific error object.

Summary

Use property overrides to add precision to your inherited types while maintaining compatibility with the base interface.