Practice & Assessment
Test your understanding of Advanced Types and Real-World Patterns
Multiple Choice Questions
5What does [K in keyof T]-?: T[K] accomplish?
What does infer do inside a conditional type?
What is the correct way to add a property to an existing library's interface?
What does noUncheckedIndexedAccess do?
What does a distributive conditional type do with a union input like string | number?
Coding Challenges
1Build a DeepReadonly mapped type
Create a utility type DeepReadonly<T> that recursively makes every property of T readonly, including nested objects and arrays. Test it with a nested structure: type Config = { server: { host: string; port: number }; features: { darkMode: boolean; betaUsers: string[] } }. Verify that DeepReadonly<Config> prevents mutation at every level. Also implement a DeepPartial<T> type that makes all properties optional recursively. Write a function mergeConfig(base: Config, overrides: DeepPartial<Config>): Config that merges deeply. Estimated time: 25 minutes.
Mini Project
Typed API Schema Builder
Build a fully typed API schema builder. Define a RouteConfig<TParams, TBody, TResponse> interface with method ('GET' | 'POST' | 'PUT' | 'DELETE'), path (string), params type (TParams), body type (TBody), and response type (TResponse). Create a typed Router class with a route<TParams, TBody, TResponse>(config: RouteConfig<TParams, TBody, TResponse>, handler: (params: TParams, body: TBody) => Promise<TResponse>) method. Use template literal types to generate typed path segments from a string: extract :param placeholders into a Record type so params are typed. Implement at least four routes: GET /users/:id, POST /users, PUT /users/:id, DELETE /users/:id. Write a mock handler for each that returns the correct response shape. Use mapped types to generate a RouteMap type and demonstrate calling each route through the router with full type inference on all inputs and outputs.
