How to Pass a TypeScript Interview: Top Questions from A to Z

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Introduction: Why TypeScript is a Must-Have for Modern Developers

TypeScript has firmly established itself as the de facto standard in enterprise development. According to Stack Overflow surveys, over 70% of frontend developers use or plan to use TypeScript. Interviews inevitably include questions on this technology — even if the vacancy is formally listed as "JavaScript Developer".

In this article, we will cover the key topics you will definitely be asked about in a technical interview: from basic types to complex generics and conditional types. The material is structured from simple to complex, allowing you to prepare systematically.



1. Basics: Types, Interfaces, and Their Differences

1.1. Primitive and Special Types

Let's start with the fundamentals. The interviewer will almost certainly ask about any, unknown, never, and void.

  • any — disables type checking. Used only as a last resort during migration.
  • unknown — a safe alternative to any. Requires type checking before use.
  • never — a type that never occurs (functions that throw exceptions or infinite loops).
  • void — the absence of a return value from a function.
function throwError(msg: string): never {    throw new Error(msg);}

function log(msg: string): void { console.log(msg);}

let data: unknown = JSON.parse('{"name":"John"}');// data.name // Error! Need a checkif (typeof data === 'object' && data !== null) { console.log((data as Record<string, unknown>).name);}


1.2. Interface vs Type: Which to Choose?

This is a classic question. Both approaches allow describing an object's structure, but there are nuances:

  • Interface — extendable (extends), supports declaration merging.
  • Type — can describe union types, intersections, and primitives. Does not support declaration merging.
// Interface - extensioninterface User {    name: string;}interface User {    age: number; // declaration merging}const user: User = { name: 'Alice', age: 30 };

// Type - uniontype Status = 'active' | 'inactive';type UserOrStatus = User | Status;

Tip: Use interface for objects and classes, and type for complex compositions.



2. Generics and Utility Types

2.1. Generics: Generic Programming

No serious interview is complete without generics. The ability to write a type that adapts to the passed argument is a sign of developer maturity.

// Simple genericfunction identity<T>(arg: T): T {    return arg;}

// Generic constraintfunction getLength<T extends { length: number }>(arg: T): number { return arg.length;}

// Generic for an arrayfunction last<T>(arr: T[]): T | undefined { return arr[arr.length - 1];}

They often ask about infer — a keyword for type inference within conditional constructs:

// Extract the element type from Promisetype Unwrap<T> = T extends Promise<infer U> ? U : T;type Result = Unwrap<Promise<number>>; // number


2.2. Utility Types

Knowledge of built-in utilities is a mandatory minimum. The interviewer may ask you to implement an equivalent manually.

  • Partial<T> — all fields become optional.
  • Required<T> — all fields become required.
  • Pick<T, K> — selects only the specified keys.
  • Omit<T, K> — omits

Blogs

Book Recommendations