Skip to content
dreamcode
dreamcode
Map
Utilities
Lesson 17 of 26
+15 XP on finish
TYPESCRIPTChapter 3 · TS Advanced

Readonly and Utility Types

TypeScript provides built-in Utility Types to transform shapes: Partial<T> makes all fields optional, Readonly<T> makes all fields immutable, Pick<T, Keys> selects specific fields, and Omit<T, Keys> removes specific fields.

Worked example

How it reads

  • Readonly<Flight> prevents writing to any property after creation
  • Pick<Flight, 'id' | 'pilot'> creates a type containing only those fields
Cloud tip: Utility types save you from duplicating similar object shapes across your code.
index.ts
TYPESCRIPT
type-checked, then run in your browser
Console
Run your code to see its output here.
YOUR TURN

Use Pick<Star, "name" | "brightness"> to type const glow = { name: "Sirius", brightness: 10 }, then log glow.brightness * 2: 20.

Press Run to check your work.