Docs
/
TypeScript
Chapter 7
07 — Objects & Interfaces
Core Concepts
- Object types — inline
{ key: Type }syntax - Interfaces — named object type declarations
- Optional properties —
key?: Type - Readonly properties —
readonly key: Type - Index signatures —
[key: string]: Typefor dynamic keys - Extending interfaces —
interface B extends A - Interface merging — declaring the same interface twice merges them
- Excess property checking — TS catches extra properties on object literals
Best Practices
- Use interfaces for object shapes you'll extend or implement
- Prefer readonly for properties that shouldn't change after creation
- Use index signatures sparingly — prefer
Record<K, V>orMap - Mark as many properties optional or readonly as truthfully possible