Like running a forEach over the properties of a type instead of an array's values.
keyof T produces a union of T's keys. [K in keyof T] iterates over each key. T[K] looks up the value type for that key.
> keyof User = "id" | "name" | "age"
> FrozenUser: { readonly id: string; readonly name: string; readonly age: number }Like running a forEach over the properties of a type instead of an array's values.
keyof T produces a union of T's keys. [K in keyof T] iterates over each key. T[K] looks up the value type for that key.
> keyof User = "id" | "name" | "age"
> FrozenUser: { readonly id: string; readonly name: string; readonly age: number }Sign in to cast your vote
Sign in to share your feedback and join the discussion.