Skip to content
tezvyn:

TypeScript & Web APIs

TypeScript, browser APIs, WebAssembly, PWAs

246 bites

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

Everything in TypeScript & Web APIs, page 4

What is the core difference between localStorage and sessionStorage?
easy2 min read

What is the core difference between localStorage and sessionStorage?

SessionStorage dies with its tab; localStorage survives restarts and shares across tabs. Example: checkout form versus theme preference.

advanced2 min read

Write a generic CreateSetters<T> that maps properties to setter methods

This tests TypeScript mapped types with key remapping and template literals. It iterates keyof T, remaps via as set plus Capitalize of string and K, and types values as setter methods. Red flag: manually typing setters or omitting string and K in Capitalize.

advanced2 min read

Implement recursive DeepReadonly<T> for nested objects and arrays

Tests recursive mapped types and conditional type narrowing. A strong answer uses a conditional to split arrays into ReadonlyArray, objects into readonly mapped types, and leaves primitives untouched.

advanced2 min read

Write a generic PickByValue<T, V> type

Tests conditional types and mapped-type key remapping. Great answer: K in keyof T as T[K] extends V ? K : never with value T[K]. Red flag: writing V extends T[K] instead, which reverses the assignability check and includes wrong keys.

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.

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

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

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.

easy2 min read

Create a User type alias from a function return type

Use typeof to grab the function type, then ReturnType to extract the return object shape.

easy2 min read

Describe a common use for Partial<T> and explain Required<T>

Partial fits PATCH updates where only some fields arrive; Required strips optionality to enforce all properties.

easy2 min read

Explain Pick versus Omit with User examples

Pick keeps listed keys; Omit drops them. Show User with id, name, email; derive Pick<User,"name"|"email"> and Omit<User,"id">.

advanced2 min read

Implement a generic PickByType<T, U> utility type

Tests mapped-type key filtering via conditional types and as remapping. Great answer: [K in keyof T as T[K] extends U ? K : never]: T[K]. Red flag: mapping all keys and setting values to never, which preserves keys instead of removing them.

advanced2 min read

Implement MyReturnType<T> using conditional types and infer

This tests type-level pattern matching with conditional types and infer. Answer uses T extends (...args: any[]) => infer R ? R : never, noting infer captures return slot, non-functions yield never. Red flag: conflating runtime values with compile-time types.

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.

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 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].

easy2 min read

Explain generic constraints and provide a length-constrained generic example

Explain that extends requires properties; show T extends { length: number }; give a generic function signature.

easy2 min read

Refactor a function using generics to accept any array type

It tests generic type parameters for preserving element types through a function boundary. Answer: declare T, accept T[], return T, and let the compiler infer the element type from the call site.

Download a large file via fetch and track ReadableStream progress
advanced2 min read

Download a large file via fetch and track ReadableStream progress

It tests streaming I/O and backpressure beyond Promise-based fetch. Acquire a reader from response.body, loop read() until done, sum chunk lengths against Content-Length, and emit progress.

When does fetch trigger a CORS preflight, and what POST is complex?
advanced2 min read

When does fetch trigger a CORS preflight, and what POST is complex?

Tests whether you know the simple-request boundary. A strong answer names the three safe POST content-types and gives a cross-origin POST with application/json plus a custom header like Authorization.

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