D
DevPrepSystematic Prep
TYPESCRIPT · MEDIUM CODEX

TypeScript Interview Questions — Medium

Real-world mechanisms, state management, edge cases, performance trade-offs, and practical coding.

50 Theory Questions7 Implementation Folios5 Free Model Answers
THEORY QUESTIONS & SOLUTIONSShowing 5 of 50 questions
Q1Compare Index Signatures and Mapped Types.
  • Index Signatures ([key: string]: any): Define arbitrary properties on objects. Flexible, but cannot restrict keys to a specific finite union of literals.
  • Mapped Types ([K in Keys]: T): Use iteration to construct an object type based on a source union of keys. Allow dynamic property construction with full type safety.
Q2What are Discriminated Unions (Tagged Unions)? Why are they powerful?
  • Definition: A union of object types where each object has a common literal property (the "discriminated" tag).
    type Shape = { kind: "circle"; radius: number } | { kind: "square"; side: number };
    
  • Power: Enables the compiler to perform complete, automatic type narrowing inside conditional or switch blocks based on checking the literal tag.
Q3How do Generics with defaults work?
  • Definition: Specifying a default fallback type inside generic parameters if no explicit type argument is passed during invocation.
    interface Config<T = string> { value: T; }
    
Q4Compare `extends` in Type Aliases vs. Interfaces.
  • Interfaces: interface A extends B {} represents static OOP-style inheritance. If properties overlap with incompatible types, it throws a compile-time error.
  • Type Aliases: Used in Conditional Types (T extends U ? X : Y), checking if a type is assignable to/compatible with another structure. Highly dynamic.
Q5Explain Mapped Type modifiers (e.g., `-readonly` or `-?`).
  • Prefix Modifiers (+ or -): Modify existing property constraints during mapping.
    • -readonly: Removes readonly from all properties.
    • -?: Removes optionality, making all properties strictly required.

Unlock the remaining 52 TypeScript (Medium) questions

You've completed the 5 free sample questions. Get unrestricted lifetime access to every question, model answer, implementation challenge, and all 27+ technologies for a single payment.

₹399 India / $9 International · One-time settlement · Zero subscription

CROSS-DIFFICULTY NAVIGATION

Continue Preparing TypeScript

TypeScript Interview Questions (Medium) | DevPrep | DevPrep