TypeScript2 min read

TypeScript Interview Questions and Type System Guide

Core TypeScript interview questions covering interfaces, type aliases, generics, utility types, discriminated unions, and type guards.

Pairlet Team•Published: •Updated:

TypeScript is the standard for modern web application engineering. Evaluating a developer's TypeScript skills requires assessing their mastery of the compile-time type system, type safety patterns, and generic utilities.

1. type Alias vs interface

  • •interface: Best for object shapes and class contracts. Supports declaration merging (re-opening interfaces across files).
  • •type: Alias for any type (primitives, unions, tuples, functions, objects). Does not support declaration merging.
TYPESCRIPT
interface User {
  id: string;
  name: string;
}

type UserWithRole = User & { role: "admin" | "member" };

2. Discriminated Unions (Tagged Unions)

Discriminated unions use a common literal property key to enable exhaustive type checking by the compiler.

TYPESCRIPT
type NetworkState =
  | { status: "loading" }
  | { status: "success"; data: string[] }
  | { status: "error"; error: Error };

function renderState(state: NetworkState) {
  switch (state.status) {
    case "loading":
      return "Loading...";
    case "success":
      return `Data items: ${state.data.join(", ")}`;
    case "error":
      return `Error: ${state.error.message}`;
  }
}

3. Built-in Utility Types

  • •Partial<T>: Makes all properties optional.
  • •Required<T>: Makes all properties required.
  • •Readonly<T>: Makes all properties readonly.
  • •Pick<T, K>: Selects a subset of properties K from T.
  • •Omit<T, K>: Removes properties K from T.
  • •Record<K, T>: Constructs an object type with keys K and values T.

4. Custom Type Guards (is Keyword)

Type guards provide runtime checks that narrow types within conditional blocks.

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

function processInput(input: unknown) {
  if (isString(input)) {
    console.log(input.toUpperCase()); // TypeScript knows input is string
  }
}

5. unknown vs any vs never

  • •any: Disables all type checking. Avoid in production code.
  • •unknown: Type-safe counterpart to any. Requires type checking before property access or invocation.
  • •never: Represents values that can never occur (e.g. function that throws or infinite loop).

Practice TypeScript Interviews Live

Evaluate TypeScript candidates in a real-time collaborative Monaco environment with browser-based TypeScript syntax handling. Create a Pairlet interview room.

Frequently Asked Questions

What is the key difference between type aliases and interfaces in TypeScript?

Interfaces support declaration merging and are optimized for object shape extension. Type aliases are more versatile, supporting unions, primitives, tuples, and mapped types.

Practice Relevant Coding Problems
Practice Live Coding

Conduct Live Coding Interviews in the Browser

No candidate sign-up required. Create a room, share the link, and code together in real time with shared code execution.

Related Articles