Interview Q&A / TypeScript

INTERVIEW Q&A · 47 QUESTIONS

TypeScript interview questions

Types, interfaces, generics and safe patterns for real codebases.

  1. Should you use an enum or a union of string literals in TypeScript?

    Both describe a fixed set of allowed values. An enum creates a real JavaScript object at runtime and its members must be referenced by name. A union of string literals like "admin" | "user" exists only at compile time, adds no code, and accepts plain strings. Many teams now prefer unions, or an as const object when they also need runtime values.

    IntermediateIn-depth4 min read
  2. What is type narrowing in TypeScript, and how do type guards work?

    Narrowing is how TypeScript refines a broad type, like string | number, to a more specific one inside a block after a check. Type guards are those checks, such as typeof, instanceof, the in operator, equality checks on a shared field, and custom functions that return a type predicate like value is User.

    IntermediateIn-depth3 min read