Type vs Interface

Type

  • Use type when defining an alias for primitive types (string, boolean, number, bigint, symbol, etc)

  • Use type when defining tuple types

  • Use type when defining function types

  • Use type when defining a union

type Nullish = null | undefined;
type Fruit = 'apple' | 'pear' | 'orange';
type Num = number | bigint;
type row = [colOne: number, colTwo: string];

Interface

  • Use interface for all object types where using type is not required (see above)

  • Using interface can extends from another interface, due to inheritance

Last updated

Was this helpful?