Skip to content
typescript questions

TypeScript · 1 of 10junior~1 min

What is the difference between type and interface in TypeScript?

#types#core

type vs interface

Both define the shape of an object, but have different capabilities.

Key differences

typeinterface
Object shapeYesYes
Primitives/unionsYesNo
Declaration mergingNoYes
ExtendsVia &Via extends
Mapped types ([K in keyof T])YesNo

Declaration merging (interface only)

ts
interface User { name: string; } interface User { age: number; } // result: { name: string; age: number; }

Union types (type only)

ts
type ID = string | number; type Status = 'active' | 'inactive' | 'banned';

Extending

ts
// interface interface Animal { name: string; } interface Dog extends Animal { breed: string; } // type type Animal = { name: string; }; type Dog = Animal & { breed: string; };

Rule of thumb: use interface for object shapes that may be extended or merged (e.g. library public APIs). Use type for unions, intersections, and utility types.

updated

did you know it?

related questions