TypeScript Interfaces: Naming the Shape of Your Data
An interface is a contract for an object's shape, caring what properties it has, not its class. Use it to define function parameters or API responses. The footgun: TypeScript allows objects with extra properties, checking only for the required ones.
A TypeScript interface is a named contract for an object's shape, enforcing structural typing ("duck typing"). If an object has the required properties and types, it's valid, regardless of extra fields. This is key for defining function parameters and API response structures. The main footgun is assuming an exact match is needed; objects with extra properties are valid as long as the contract is met.
Read the original → typescriptlang.org
- #typescript
- #types
- #interface
- #contracts
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.