interface User { id: string; name: string } describes object shapes. Interfaces can extend others and support optional properties with ?.
Declaration merging
Interfaces with the same name merge—useful for augmenting third-party types. Type aliases cannot merge, which is why libraries often export interfaces.
Self-check
- Extend a
BaseEntityinterface withcreatedAt: stringon aPosttype.
Challenge
Product card
- Define an
interface Productwithid,title,price. - Create one object and print
title — $price.
Done when: formatted price line appears in terminal.
Interview prep
- interface vs type alias?
Interfaces excel at object extension; type aliases can express unions, tuples, and mapped types.