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 Explain `any`, `unknown` and `never`.

    any disables type checking for a value; unknown is the type-safe top type: anything can be assigned to it, but you must narrow it before use; never is the bottom type for values that never occur…

  2. Most asked Explain conditional types and the `infer` keyword.

    Conditional types (T extends U ? X : Y) choose a type based on assignability. infer declares a type variable inside the extends clause to capture part of a type, e.g. a function's return type or a…

  3. Most asked How do function overloads work in TypeScript and when are they better than unions?

    Overloads declare multiple call signatures for one implementation, letting the return type depend on the argument types. The implementation signature must be compatible with all overloads and isn't…

  4. Most asked Explain `keyof`, `typeof` (in type position) and indexed access types.

    keyof T produces a union of T's property keys; typeof value (in a type position) gets the type of a runtime value; indexed access T[K] looks up the type of a property (or T[number] for array…

  5. How does type inference work in TypeScript, and when should you annotate explicitly?

    TypeScript infers types from initializers, return statements and context (contextual typing for callbacks). Annotate function parameters, public API boundaries and exported functions' return types;…

  6. How do optional chaining (`?.`) and nullish coalescing (`??`) work with types?

    a?.b returns undefined if a is null/undefined, and TypeScript adds | undefined to the resulting type. a ?? b uses b only when a is null or undefined (unlike ||, which also falls back on 0, '' and…

  7. Explain `void` as a return type and why a callback typed `() => void` can return a value.

    void means the return value should be ignored. For function types (like callback parameters), a function returning a value is still assignable to () => void, so arr.forEach(x => list.push(x))…

  8. How are tuples typed in TypeScript, including labeled and variadic tuples?

    Tuples are fixed-length arrays with per-position types ([string, number]). They support optional elements ([string, number?]), rest elements ([string, ...number[]]), labels ([name: string, age:…

  9. Can Node.js run TypeScript directly?

    Yes. Recent Node versions (23.6+, and 22.18+ by default) can run .ts files via built-in type stripping, which removes erasable type annotations. They don't type-check, and they don't support…

  10. How do path aliases (`@/components`) work, and what's the common pitfall?

    compilerOptions.paths (with baseUrl optional since TS 4.1) tells the type checker how to resolve aliases, but it doesn't rewrite imports in emitted JavaScript. Your bundler or runtime must also…

  11. How does TypeScript type `this`?

    Methods can declare a this parameter (function f(this: Window)) to type the calling context; polymorphic this types (method(): this) let fluent APIs return the subclass type; and noImplicitThis…

  12. Explain `Exclude`, `Extract` and `NonNullable`.

    Exclude<U, X> removes union members assignable to X, Extract<U, X> keeps only those members, and NonNullable<T> removes null and undefined. They're distributive conditional types.

  13. How are generators and iterators typed?

    Generator functions return Generator<Yield, Return, Next> (or AsyncGenerator<...>); iterables implement Iterable<T> via Symbol.iterator. TypeScript infers these from yield expressions in most cases.

  14. Can you get TypeScript checking in plain JavaScript files?

    Yes. Enable checkJs (or add // @ts-check) and write types in JSDoc comments (@param, @returns, @typedef, @template), and TypeScript will type-check .js files without a build step.

  15. Can you pass a `readonly string[]` to a function expecting `string[]`?

    No. A mutable array type allows push, so assigning a readonly array to it would allow mutation; the reverse (passing string[] to readonly string[]) is fine. Accept readonly T[] in parameters when…

  16. How can generics make a builder pattern type-safe (e.g., tracking which fields are set)?

    Have each builder method return a new builder type that records the set fields in a type parameter (e.g., Builder<T & { name: string }>), and only expose build() when required fields are present.

  17. How can `Record<Union, T>` catch bugs when a union grows?

    A Record<Status, string> object literal must provide a value for every member of Status, so adding a new status causes compile errors at every lookup table that needs updating.

  18. How are getters, setters and the `accessor` keyword typed?

    Getters and setters declare property types (since TS 5.1 they may have unrelated types if explicitly annotated). The accessor keyword (TS 4.9, standard decorators) creates auto-accessors backed by…

  19. How does the `in` operator narrow union types?

    'prop' in obj narrows a union to members that declare prop (and since TS 4.9, can also add the property to an unlisted type as unknown), which is useful for unions without a shared discriminant.

  20. How do you safely work with DOM elements in TypeScript?

    document.querySelector returns Element | null (or a specific type for tag selectors like 'input'), so handle null and narrow with instanceof HTMLInputElement or a generic…

Was this page helpful?

Report a mistake