TypeScript15 min read

TypeScript Coding Interview: 12 Problems to Practice

12 practical TypeScript coding interview exercises with solutions, including typed event emitters, Result types, deep readonly, and code review scenarios.

Pairlet TeamPublished: 2026-09-08

Evaluating TypeScript proficiency requires going beyond simple JavaScript algorithms with added type annotations. Strong candidates demonstrate type-safe design patterns, zero unnecessary any usage, and proper generic constraints.

Problem 1: Strongly Typed Event Emitter

Implement a type-safe event emitter where event names map to expected payload argument types.

typescriptPairlet Snippet

class TypedEventEmitter { private listeners: { [K in keyof Events]?: Array<(payload: Events[K]) => void> } = {};

on(event: K, listener: (payload: Events[K]) => void): void { if (!this.listeners[event]) { this.listeners[event] = []; } this.listeners[event]!.push(listener); }

emit(event: K, payload: Events[K]): void { const callbacks = this.listeners[event]; if (callbacks) { callbacks.forEach(cb => cb(payload)); } } }

// Usage Example: interface AppEvents { userLogin: { userId: string; timestamp: number }; error: { message: string }; }

const emitter = new TypedEventEmitter(); emitter.on("userLogin", (data) => console.log(data.userId)); // emitter.emit("userLogin", { userId: 123 }); // Error: Type number is not assignable to string ``` *Try the Event Emitter exercise live on Pairlet.*

Problem 2: Type-Safe Result Union (Result<T, E>)

Model success and error outcomes without relying on thrown exceptions.

typescriptPairlet Snippet
type Result<T, E = Error> =
  | { ok: true; value: T }

function ok(value: T): Result { return { ok: true, value }; }

function err(error: E): Result { return { ok: false, error }; } ```

Problem 3: DeepReadonly<T> Utility Type

typescriptPairlet Snippet
type DeepReadonly<T> = T extends Function
  ? T
  : T extends object
  ? { readonly [K in keyof T]: DeepReadonly<T[K]> }
  : T;

Problem 4: TypeScript Code Review Challenge

Spot the anti-patterns in the following snippet:

typescriptPairlet Snippet
// Flawed implementation:
async function fetchUser(id: any): Promise<any> {
  const res = await fetch(`/users/${id}`);
  const data = await res.json();
  return data as any;
}

Issues: Heavy reliance on any, lack of error boundary check on res.ok, and unsafe type assertions. *Explore the Bad TypeScript Design code review problem on Pairlet.*

---

Practice TypeScript Interviews Run TypeScript coding interviews in a collaborative browser workspace with real-time feedback. [Create a free Pairlet interview room](https://www.pairlet.dev/interview/new).

Frequently Asked Questions

Why test TypeScript specific problems instead of plain JavaScript?

TypeScript coding problems evaluate how candidates construct maintainable type contracts, avoid 'any' escape hatches, handle nullability, and model domain data accurately at compile time.

Practice Relevant Coding Problems
Practice Live Coding

Conduct Live Coding Interviews with Zero Friction

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

Related Articles