Skip to main content
TYPESCRIPT-BASICS5 MIN READ

Choose interface or type by contract shape

Use `interface` and `type` intentionally for everyday object and union modeling.

The move: Model object contracts and state choices differently. An object contract answers: what properties and methods must this thing provide? That is where interface is often clearest. It reads as a shape another object can satisfy, and it supports extension when the domain model grows. A type alias answers a broader question: what named shape do I want to reuse? It can be an object, but it shines when the shape is a union, tuple, primitive alias, intersection, or utility-derived type. type SortDirection = 'asc' | 'desc' is clearer than an object wrapper that pretends a two-value state is…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us