keyof and typeof
Keyof Typeof
π¨βπΌ You've used type operators to extract and work with types!
π¦ The
as const trick is essential for deriving literal union types from
arrays:// Without as const
const colors = ['red', 'blue'] // Array<string>
type Color = (typeof colors)[number] // string π’
// With as const
const colors = ['red', 'blue'] as const // readonly ['red', 'blue']
type Color = (typeof colors)[number] // 'red' | 'blue' π
This pattern is used everywhere for configuration and constants.


