5 exercises on TypeScript generics pattern vocabulary.
0 / 5 completed
1 / 5
What does the infer keyword do inside a conditional type?
infer: used in T extends SomeType<infer U> ? U : never. TypeScript pattern-matches and binds U to the inner type, enabling utilities like ReturnType<T> or Awaited<T>.
2 / 5
What is a generic constraint expressed with extends?
Generic constraint:function fn<T extends { id: number }>(x: T) ensures T always has an id property. Without the constraint TypeScript cannot know which members are safe to access.
3 / 5
What does mapped type{ [K in keyof T]: ... } produce?
Mapped type: iterates over every key in T and computes a value type. Built-ins like Partial<T>, Required<T>, and Readonly<T> are all implemented as mapped types.
4 / 5
What does the satisfies operator (TypeScript 4.9) do differently from a type annotation?
satisfies: unlike const x: T = ... which widens to T, const x = ... satisfies T keeps the exact literal type. You get type-safety AND precise inference for downstream use.
5 / 5
What is a template literal type in TypeScript?
Template literal type:type EventName = `on${Capitalize<string>}` produces a type that matches strings like onClick or onChange. Combined with mapped types it can derive typed event maps from model keys.