Indexed Access Types
T[K] looks up the type of property K on type T at the type level; indexing with a union of keys yields the union of property types, and T[number] extracts an array's element type. Combined with keyof it gives fully typed property access: <K extends keyof T>(obj: T, key: K) => T[K].
This Concept is waiting for its first lesson!
T[K] looks up the type of property K on type T at the type level; indexing with a union of keys yields the union of property types, and T[number] extracts an array's element type. Combined with keyof it gives fully typed property access: <K extends keyof T>(obj: T, key: K) => T[K].
Are you a teacher? Sign in to start contributing.
Sign In