Script Valley
TypeScript: Complete Course from Zero
Advanced Types and Real-World Patterns/Assessment

Practice & Assessment

Test your understanding of Advanced Types and Real-World Patterns

Multiple Choice Questions

5
1

What does [K in keyof T]-?: T[K] accomplish?

2

What does infer do inside a conditional type?

3

What is the correct way to add a property to an existing library's interface?

4

What does noUncheckedIndexedAccess do?

5

What does a distributive conditional type do with a union input like string | number?

Coding Challenges

1
1

Build 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.

Hard

Mini Project

1

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.

Hard
Practice & Assessment โ€” Advanced Types and Real-World Patterns โ€” TypeScript: Complete Course from Zero โ€” Script Valley โ€” Script Valley