Manuals / TypeScript / Chapter 3
A · Setup · beginner · Week 1–2 · Chapter 3 of 11
Types, interfaces & inference
type and interface define object shapes. Use interface for object contracts, type for unions and computed shapes. Inference fills types when obvious. Annotate public API boundaries; let inference handle locals.
Path progress20%
Step 1 of 5
Object shapes
interface User { id: number; name: string; email?: string }. Optional with ?. readonly for immutability hints.
Example
interface User {
id: number
name: string
email?: string
readonly createdAt: string
}Do this now
Define User, Product, and Order interfaces for a shop domain. Include optional fields.
Was this step clear?
Chapter learning outcomes
- type vs interface
- Optional & readonly
- Type inference
- Function types
- Literal types
Clear these before you leave
Side quest
Typed models
Create types/models.ts with 5+ interfaces for your fetch app domain. Use them in api.ts.