type
Interfaces
can't express unions
, mapped types, or conditional types.
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
.
You should use types
by default unless you need a specific feature of interfaces.
type
and interface
together,interface
over type
when type extension
is involvedWhen 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