Skip to content
tezvyn:

TypeScript & Web APIs

TypeScript, browser APIs, WebAssembly, PWAs

61 bites

Test yourself: Top 30 intermediate TypeScript & Web APIs interview questionsMultiple choice, with the correct answer and why it is correct on every question. Free, no sign-in.

Intermediate interview questions in TypeScript & Web APIs, page 2

How do you fetch from three APIs using Promise.all versus allSettled?
intermediate2 min read

How do you fetch from three APIs using Promise.all versus allSettled?

Promise.all parallelizes but rejects on first failure. allSettled returns every outcome with status, value, and reason.

How do you type an async function return in TypeScript?
intermediate2 min read

How do you type an async function return in TypeScript?

This tests if you know async functions always return Promise<T>. A great answer: annotate Promise<User>, return User from the body, and note TypeScript implicitly wraps it. A red flag is omitting Promise and typing the return as just User.

Write a typed async fetchUser with error handling
intermediate2 min read

Write a typed async fetchUser with error handling

Tests promise-based fetch plus TypeScript return-type contracts. A strong answer checks response.ok before response.json() and types the return as Promise<User>. A red flag is swallowing 4xx/5xx errors silently.

How do you include a JWT in a fetch request?
intermediate2 min read

How do you include a JWT in a fetch request?

Tests knowledge of the fetch options object and Bearer scheme syntax. A strong answer sets headers: { Authorization: Bearer <token> } as the second argument and notes fetch does not auto-attach tokens. Red flag: omitting Bearer or hardcoding secrets.

intermediate2 min read

How do you handle an API returning 200 for success and failure?

This tests TypeScript narrowing and runtime validation of ambiguous 200 responses. A strong answer uses a discriminated union, narrows with a type guard, and validates shape before branching. Red flag: casting the body with as and skipping runtime checks.

Create a generic fetchJson wrapper with typed response and error handling
intermediate2 min read

Create a generic fetchJson wrapper with typed response and error handling

Generic T parameter, optional RequestInit, throw if !res.ok, return res.json() as Promise<T>.

intermediate2 min read

Write a generic type-safe getProperty using keyof

Command of TypeScript generics and keyof for compile-time property access. Declare generic T, accept key as keyof T, and return T[K].

intermediate2 min read

Create a generic State class with getState and setState

Write class State<T> with private T, constructor(T), getState(): T, and setState(T).

intermediate2 min read

Write a generic fetchJSON<T> wrapper and explain its type safety benefits

Tests preserving type info across async boundaries via generics. Outline: write fetchJSON<T> returning Promise<T>, note response.json() is any, and show T lets callers lock in the response shape for compile-time checks.

intermediate1 min read

Generic merge with an intersection return type

Use two type parameters T and U, return T & U, spread both objects; note later spread wins on key collisions and the type may not reflect that.

intermediate2 min read

Write a generic MakeOptional<T> mapped type without using Partial

This tests mapped type mechanics and the optionality modifier. A strong answer iterates over keyof T, adds the ? modifier, and preserves the original type via indexed access. A red flag is suggesting Object.assign or saying you would just use Partial.

intermediate2 min read

Create TerminalStatus from Status using Exclude or Extract

This tests conditional type mechanics and whitelist versus blacklist thinking. Extract selects matches by assignability; Exclude removes others. Prefer Extract when the desired set is explicit. Red flag: claiming they are equivalent or only knowing Exclude.

intermediate2 min read

Implement MyParameters<T> using conditional types and infer

Tests if you can extract parameter types with infer. A strong answer matches T against a callable signature, uses infer to bind parameters into a tuple, and defaults to never for non-functions. Red flag: using any or indexing without inference.

intermediate2 min read

Implement the built-in NonNullable<T> utility type from scratch

Tests conditional type distribution and union filtering. A strong answer uses distributive conditional types to map null and undefined to never while preserving other union members.

What are localStorage's capacity and synchronous blocking limitations?
intermediate2 min read

What are localStorage's capacity and synchronous blocking limitations?

This tests Web Storage API trade-offs and main-thread blocking. A strong answer notes synchronous calls block the main thread; cites a finite per-origin quota; and names IndexedDB for async needs. Red flag: calling it a database or ignoring UI freezes.

intermediate2 min read

Design a type-safe generic localStorage wrapper in TypeScript

Generic getItem<T> returns T|null via JSON.parse, setItem<T> stringifies, and a key-to-type map enforces safety.

Explain IndexedDB transactions and readonly vs readwrite modes
intermediate2 min read

Explain IndexedDB transactions and readonly vs readwrite modes

Every operation needs a transaction; readonly allows concurrent readers, readwrite is exclusive; they auto-commit when idle.

Write an IndexedDB add function with transaction error handling
intermediate2 min read

Write an IndexedDB add function with transaction error handling

Tests IndexedDB request-transaction lifecycle and event-driven error propagation. Answers open a transaction, call add(), and wire onsuccess/onerror on the request plus onabort/onerror on the transaction. Red flag: ignoring onabort or duplicate-key throws.

SPA back button: what event fires and how do you handle it?
intermediate2 min read

SPA back button: what event fires and how do you handle it?

Tests History API literacy. Strong answer: popstate event, PopStateEvent type, restore UI via event.state, and zero-delay setTimeout for DOM sync. Red flag: confusing popstate with pushState or using hashchange for modern History API routing.

Pass data to a Web Worker and transfer an ArrayBuffer efficiently
intermediate2 min read

Pass data to a Web Worker and transfer an ArrayBuffer efficiently

Tests postMessage clone versus transferable objects for zero-copy transfer. Good answers note postMessage copies by default, but ArrayBuffer can move via transfer list, neutering the original.

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles