TypeScript Master (50 Qs)•Part 2: Advanced Type System & Metaprogramming (Mid-Level)
Explain Standard Utility Types: `Partial`, `Required`, `Readonly`, `Record`.
mid LevelCode ExampletypescriptAdvanced Type System
In Simple Words:
Partial<T>: Makes all properties optional (?).Required<T>: Removes all optional modifiers (-?).Readonly<T>: Addsreadonlyto all properties.Record<K, T>: Constructs an object type with property keysKand value typeT.
typescript
interface Config { port: number; host?: string; }
type AllOptional = Partial<Config>; // { port?: number; host?: string; }
type AllRequired = Required<Config>; // { port: number; host: string; }
type RouteMap = Record<string, () => void>;