Interview Q&A · questions with model answers

TypeScript Developer Interview Questions

Part of the study plan for: Frontend Engineer · Full Stack Engineer

Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.

  1. Most asked What is TypeScript and what problems does it solve?

    TypeScript is a statically typed superset of JavaScript that adds a type system and compiles (by erasing types) to plain JavaScript. It catches type errors at compile time, improves editor tooling…

  2. Most asked What are the differences between `interface` and `type` aliases?

    Both can describe object shapes and be extended. Interfaces support declaration merging and extends, which reads well for object/class contracts; type aliases can name any type, including unions,…

  3. Most asked What is structural typing in TypeScript?

    TypeScript checks compatibility by shape (structure), not by declared names: a value is assignable to a type if it has all the required members with compatible types, regardless of which class or…

  4. Most asked What is type narrowing and what techniques does TypeScript support?

    Narrowing refines a broad type to a more specific one within a code branch, based on control-flow analysis of checks like typeof, instanceof, in, equality, truthiness, discriminant properties, and…

  5. Most asked What are discriminated unions and why are they powerful?

    A discriminated (tagged) union is a union of object types sharing a literal property (the discriminant, e.g., type or status). Checking that property narrows to the exact variant, and exhaustiveness…

  6. Most asked What are generics and how do constraints work?

    Generics are type parameters (<T>) that let functions, classes and types work over many types while preserving type relationships. Constraints (<T extends Something>) restrict what T can be so you…

  7. Most asked What are mapped types? Show how `Partial` or `Readonly` could be implemented.

    Mapped types create new types by iterating over keys: { [K in keyof T]: ... }. Modifiers ?, readonly, -? and -readonly add or remove optionality and readonly-ness, and as clauses remap or filter keys.

  8. Most asked What does `as const` do?

    as const makes TypeScript infer the narrowest possible type: literal types instead of string/number, readonly properties, and readonly tuples instead of arrays.

  9. Most asked What are union types and how do you work with them safely?

    A union type (A | B) describes a value that can be one of several types. You can only use members common to all variants until you narrow the value with checks.

  10. What are template literal types?

    Template literal types build string literal types using template syntax, e.g. ${Method} /api/${Resource} , and combine with unions (producing all combinations) and intrinsic helpers like Uppercase,…

  11. What are covariance and contravariance in TypeScript function types?

    With strictFunctionTypes, function parameter types are checked contravariantly (a function accepting a wider type can be used where a narrower parameter is expected), while return types are…

  12. What are declaration files (`.d.ts`) and how do you type a JavaScript library without types?

    Declaration files contain only type information (no implementation) describing a JavaScript module's API. If a library lacks types, install @types/<lib> from DefinitelyTyped, or write a declare…

  13. What are `import type`, `isolatedModules` and `verbatimModuleSyntax`?

    import type { X } imports only types and is always erased. isolatedModules ensures each file can be transpiled independently (as esbuild/SWC/Babel do) by flagging constructs that need cross-file…

  14. What are index signatures and how do they relate to `Record`?

    An index signature ({ [key: string]: number }) describes objects with arbitrary keys of a given type; Record<K, V> is a utility producing a mapped type over K, which is exhaustive when K is a finite…

  15. What are project references and when do you use them?

    Project references split a codebase into multiple tsconfig projects (composite: true) that reference each other, enabling tsc --build to compile incrementally in dependency order and enforcing…

  16. What are excess property checks and when do they apply?

    When you assign a fresh object literal to a typed target, TypeScript errors on properties not declared in the target type, which catches typos. The check doesn't apply to non-literal values…

  17. What changed with decorators in TypeScript 5.0?

    TypeScript 5.0 implemented the standard ECMAScript (Stage 3) decorators, which work without experimentalDecorators and have a different API (decorator functions receive the value and a context…

  18. What are `using` declarations (TypeScript 5.2)?

    using and await using implement Explicit Resource Management: when the block exits, the resource's Symbol.dispose (or Symbol.asyncDispose) is called automatically, like try/finally cleanup.

  19. What are `const` type parameters (TS 5.0) and `NoInfer` (TS 5.4)?

    <const T> makes TypeScript infer literal/readonly types for arguments as if the caller wrote as const. NoInfer<T> blocks a particular usage of T from contributing to inference, so inference comes…

  20. What is `strictPropertyInitialization` and the definite assignment assertion (`!:`)?

    With strictPropertyInitialization, class properties must be initialized in the declaration or constructor. The definite assignment assertion prop!: Type tells the compiler the property will be set…

  21. What do `Parameters`, `ConstructorParameters`, `InstanceType` and `ReturnType` give you?

    Parameters<F> is a tuple of a function's parameter types, ConstructorParameters<C> the same for a class constructor, InstanceType<C> the type of new C(), and ReturnType<F> the function's return type.

  22. What does typescript-eslint add beyond the compiler?

    It lints TypeScript code with type-aware rules that the compiler doesn't enforce, such as no-floating-promises, no-misused-promises, no-unsafe-* (tracking any), switch-exhaustiveness-check and…

  23. What is the Result pattern in TypeScript and when is it preferable to exceptions?

    A Result type is a discriminated union like { ok: true; value: T } | { ok: false; error: E } returned instead of throwing, which makes failure cases explicit in the type system and forces callers to…

  24. What is a `unique symbol` type?

    unique symbol is a subtype of symbol tied to one specific const declaration, allowing symbols to be used as typed, collision-free property keys and brands.

  25. What do the `target` and `lib` compiler options control?

    target sets the JavaScript version emitted (syntax is downleveled for older targets), while lib controls which built-in type declarations are available (e.g., ES2023, DOM). lib doesn't add polyfills.

  26. What are generic defaults and when are they useful?

    Generic type parameters can have defaults (<T = string>), used when the caller doesn't specify and inference can't determine them, which makes APIs simpler while still allowing customization.

  27. What are phantom types and how do they relate to branding?

    A phantom type parameter appears in a type but not in its runtime data, encoding extra compile-time information, such as Distance<'km'> vs Distance<'mi'> or Validated<Email>, so unvalidated values…

  28. What is contextual typing?

    Contextual typing is when TypeScript infers the types of a function's parameters from where the function is used, e.g. the parameter of a callback passed to array.map or an event handler prop, so…

  29. What is literal type widening?

    When a literal is assigned to a mutable location (let, object properties, array elements), TypeScript widens its type ('GET' → string), which can cause errors when passing it to a parameter…

  30. What is the native TypeScript compiler port (TypeScript 7 / tsgo)?

    Microsoft is porting the TypeScript compiler and language service from TypeScript/JavaScript to Go, aiming for roughly 10x faster builds and editor responsiveness through native code and…

  31. What do you do when TypeScript infers a generic type parameter too broadly or as `unknown`?

    Provide better inference sources (an argument that mentions T), add constraints, use const type parameters for literals, use NoInfer to block unwanted inference sites, or specify the type argument…

  32. What should teams expect from TypeScript 6.0?

    TypeScript 6.0 is a transition release before the native Go-based TypeScript 7: it aligns defaults with modern practice and deprecates legacy options (for example older module/target settings), so…

  33. What TypeScript practices do you look for in code reviews?

    No unexplained any or as casts, runtime validation at boundaries, discriminated unions for state, exhaustive handling, precise but readable types (no type gymnastics without need), explicit return…

Was this page helpful?

Report a mistake