5 exercises on TypeScript built-in utility types — Awaited, Parameters, ReturnType, Extract, and Exclude.
0 / 5 completed
1 / 5
What does the Awaited<T> utility type do?
Awaited: introduced in TypeScript 4.5 to replace the fragile ReturnType<typeof fn> workaround. It handles nested promises too — Awaited<Promise<Promise<number>>> yields number.
2 / 5
What does Parameters<T> return?
Parameters:Parameters<(x: number, y: string) => void> yields [number, string]. Useful for creating wrappers that accept the same arguments as an existing function without re-declaring the signature.
3 / 5
What is the difference between Extract<T, U> and Exclude<T, U>?
Extract vs Exclude: given T = "a" | "b" | "c" and U = "a" | "c", Extract<T,U> gives "a" | "c"; Exclude<T,U> gives "b". Think of Extract as set intersection and Exclude as set difference.
4 / 5
What does ReturnType<T> extract?
ReturnType: implemented as T extends (...args: any) => infer R ? R : never. Often used when you want the return shape of a factory or query function without importing its return type explicitly.
5 / 5
What does ConstructorParameters<T> give you?
ConstructorParameters:ConstructorParameters<typeof MyClass> returns the argument types the constructor expects. Combined with ...args: ConstructorParameters<typeof Cls> you can build typed factory wrappers without duplicating the signature.