AI Hints
Home›TypeScript Tutorial›Aliases and Interfaces
TypeScript · Lesson 24 of 120

Aliases or Interfaces

How to choose.

⏱ 2 min read▶ Video at 19:01🎓 Free
Watch this lesson in the TypeScript courseWatch on YouTube ↗Full TypeScript course

Aliases and interfaces overlap a lot, so which should you use? For objects, either works. But each can do a few things the other can't.

Aliases or Interfaces
From the video: Aliases or Interfaces
  • They overlap
  • Either works
  • Small differences

The differences

Only aliases can name unions, tuples, and simple types. Only interfaces can be reopened, to add more properties later. Both can be extended. For everyday objects, pick one style, and stay consistent.

Featuretypeinterface
Object shapesyesyes
Unions, tuplesyesno
Reopen to addnoyes
Extendwith &with extends

A simple rule

Use interfaces for object shapes, especially in libraries. Use aliases for everything else, like unions. The most important thing is being consistent across your project.

keyvalue
Objectsinterface
Unionstype
Librariesinterface
Most importantconsistency

Summary

Use interfaces for objects, aliases for unions and the rest, and be consistent. Next, extending interfaces.

Key takeaways
  • Objects: interface
  • Unions: type
  • Be consistent
Next up: Extending Interfaces — build on a shape