Skip to content

Instantly share code, notes, and snippets.

@lreverchuk
Last active June 13, 2026 10:58
Show Gist options
  • Select an option

  • Save lreverchuk/a5f7acd8b773a325d3d6d987433a907f to your computer and use it in GitHub Desktop.

Select an option

Save lreverchuk/a5f7acd8b773a325d3d6d987433a907f to your computer and use it in GitHub Desktop.
TypeScript Interview Questions and Answers: Types & Generics

TypeScript Interview Questions: Types, Generics & Config With Answers

A focused set of TypeScript interview questions with concise, correct answers, covering the type system, generics, utility types, narrowing, and how TS relates to JavaScript. Useful for interview prep or screening candidates.

Fundamentals

What is TypeScript? A statically typed superset of JavaScript that compiles to plain JS. It adds optional types caught at compile time, catching bugs before runtime. All valid JS is valid TS.

interface vs type? Both describe object shapes. interface can be extended and reopened (declaration merging); type is more flexible, it can describe unions, intersections, primitives, and tuples. Use interface for object/class contracts, type for everything else.

any vs unknown vs never? any disables type checking (avoid). unknown is type-safe any, you must narrow before use. never represents values that can't occur (e.g. a function that always throws).

What is type inference? TS deduces types automatically: let x = 5 infers number. You don't always need annotations.

What are union and intersection types? Union A | B means "A or B". Intersection A & B means "A and B combined".

Generics

What are generics? Reusable type parameters that preserve type information:

function identity<T>(value: T): T { return value; }
const n = identity(5);        // T inferred as number

What are generic constraints? <T extends { id: number }> restricts T to types with an id. Lets you use those properties safely inside the generic.

keyof and indexed access? keyof T is the union of T's property names. T[K] is the type of property K. Together they enable type-safe property access:

function get<T, K extends keyof T>(obj: T, key: K): T[K] {
  return obj[key];
}

Utility types

Utility Does
Partial<T> all properties optional
Required<T> all properties required
Readonly<T> all properties read-only
Pick<T, K> subset of properties
Omit<T, K> all properties except K
Record<K, V> object with keys K and values V
ReturnType<F> return type of a function
Parameters<F> tuple of a function's parameter types
type User = { id: number; name: string; email: string };
type UserPreview = Pick<User, "id" | "name">;
type UserUpdate = Partial<User>;

Narrowing & guards

What is type narrowing? Refining a broad type to a specific one using control flow, typeof, instanceof, in, truthiness, or custom guards.

What is a type guard? A function returning arg is Type that tells the compiler the narrowed type:

function isString(x: unknown): x is string {
  return typeof x === "string";
}

What are discriminated unions? Unions sharing a literal "tag" field that TS uses to narrow:

type Shape =
  | { kind: "circle"; r: number }
  | { kind: "square"; side: number };
function area(s: Shape) {
  switch (s.kind) {
    case "circle": return Math.PI * s.r ** 2;
    case "square": return s.side ** 2;
  }
}

Config & practical

What does strict mode enable? A bundle of strict checks: strictNullChecks, noImplicitAny, strictFunctionTypes, and more. Always enable it on new projects.

What is strictNullChecks? Makes null and undefined distinct types you must handle explicitly, eliminates a huge class of runtime errors.

What are enums, and are they recommended? Named constant sets. Many teams prefer union string literal types (type Status = "active" | "inactive") for smaller output and simpler typing.

What is the difference between as and <> casting? Both assert a type: value as string or <string>value. Prefer as (the angle-bracket form clashes with JSX).

Common gotchas

Type vs value space: types are erased at compile time, you can't use them at runtime. any leaks: one any can silently disable checking downstream. Structural typing: TS matches by shape, not by name, two differently named types with the same shape are compatible.

Quick checklist for candidates

Topic Can they explain…
type vs interface when to use each
Generics constraints, keyof, T[K]
Utility types Partial/Pick/Omit/Record
Narrowing guards + discriminated unions
unknown vs any type safety
strict mode strictNullChecks

Maintained by the team at EchoGlobal. Hiring TypeScript talent? See our curated lists of Top TypeScript Developers, Top JavaScript Engineers, and Top Node.js Experts on GitHub, or hire pre-vetted developers in days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment