Skip to main content
InterviewHubPRO
Section Overview
Q20

Question 20 of 50

Part 2: Advanced Type System & Metaprogramming (Mid-Level)

40%
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>: Adds readonly to all properties.
  • Record<K, T>: Constructs an object type with property keys K and value type T.
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>;