HomeToolsAbout

Type vs Interface

type

Interfaces can't express unions, mapped types, or conditional types.

  • Type aliases can express any type.

interface

interface is always in object shape, not primitives.

  • interfaces can use extends to inherit from another interface.

It's a good rule of thumb to think of using interface when you consciously need extends.

When to use what

You should use types by default unless you need a specific feature of interfaces.

  • you can technically blend and use type and interface together,

interface over type when type extension is involved

When you're working with objects that inherit from each other, use interfaces.

  • extends makes TypeScript's type checker run slightly faster than using &.
// extending interface interface IShrimpFriedRice extends IFriedRice { ingredients: IShrimp, } // extending type type Latte = { liquid: Coffee } & Milk
AboutContact