HomeToolsAbout a20k

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

When to use what

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

  • It's also noting you can 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
© VincentVanKoh