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

intermediate2 min read

What is noImplicitAny and why is it best practice?

State that noImplicitAny errors when inference fails, forcing explicit types instead of plain any.

intermediate2 min read

Explain the difference between any and unknown, and demonstrate type-safe narrowing

This tests your grasp of TypeScript top types: any disables checking while unknown forces narrowing. A strong answer defines both, accepts unknown, and uses typeof or a type guard before operating. Red flag: saying they are equivalent or relying on as casts.

intermediate2 min read

How do you type and guard a string-or-string-array argument?

Tests union typing and runtime narrowing. Annotate as string | string[], then branch with Array.isArray(). Strong answers note typeof returns "object" for arrays and that assertions bypass safety.

intermediate2 min read

Key differences: type alias vs interface for object shapes

Tests your grasp of TypeScript extensibility and declaration merging. Contrast interfaces' extends and open merging against type aliases' unions, intersections, and primitives; prefer interfaces for public APIs and types for unions or mapped types.

Describe the difference between DOMContentLoaded and window.load
intermediate2 min read

Describe the difference between DOMContentLoaded and window.load

This tests critical rendering path knowledge. DOMContentLoaded fires after HTML parsing and deferred scripts, while load waits for all subresources; use the former to bind UI early.

Describe event delegation and implement a single ul click handler in TypeScript
intermediate2 min read

Describe event delegation and implement a single ul click handler in TypeScript

Add one listener to the ul, use event.target plus closest to find the li, and type it as MouseEvent.

Explain DOM event capturing and bubbling with addEventListener
intermediate2 min read

Explain DOM event capturing and bubbling with addEventListener

Tests DOM event propagation and addEventListener phase selection. Core: capture moves root-to-target, bubble moves target-to-root, useCapture or options.capture sets it. Red flag: saying events only bubble or confusing stopPropagation with preventDefault.

What are the key differences between NodeList and HTMLCollection?
intermediate2 min read

What are the key differences between NodeList and HTMLCollection?

Tests DOM snapshot vs live binding: querySelectorAll returns a static NodeList, getElementsByTagName returns a live HTMLCollection. Strong answers note childNodes is a live NodeList and warn against caching length during DOM mutation.

intermediate2 min read

How would you use an enum to represent API statuses?

What it tests: TypeScript enum runtime behavior and API serialization trade-offs. Strong answer: define a string enum with exact API values, contrast readable wire format vs opaque numeric values.

intermediate2 min read

How would you model a WebSocket message discriminated union in TypeScript?

This tests TypeScript discriminated union narrowing. Define interfaces with readonly literal kind fields, union them, and narrow with switch or if checks. A red flag is typing kind as generic string or using type assertions instead of narrowing.

intermediate3 min read

Write a generic ApiResponse<T> type with success and error states

Define two interfaces sharing a status literal, one with data: T and the other with error: { code; message; }.

intermediate2 min read

How would you combine BaseRecord and PostContent into a Post type?

This tests TypeScript type composition for API resources. A strong answer proposes an intersection type or interface extends, then discusses overlap conflicts and the type versus interface trade-off.

intermediate2 min read

How do you type a GeoJSON Coordinate tuple and LineString array?

Tests fixed-length tuple typing versus flexible arrays in TypeScript. A strong answer uses [number, number] for Coordinate, then Coordinate[] for LineString, and explains why number[] loses length safety. Red flag: using number[] or objects instead of tuples.

intermediate2 min read

How do you type a function with string and number overloads?

Tests if you know overloads are public API and the implementation uses a union. Answer: write process(string):string and process(number):number overloads, then implement with string|number and narrow. Red flag: exposing only the implementation signature.

Why does this lose context in class callbacks and two TypeScript fixes?
intermediate2 min read

Why does this lose context in class callbacks and two TypeScript fixes?

This tests runtime this binding. Explain that regular functions get this from the call site, so passing a method strips its object context. Fix with an arrow property or constructor bind. Red flag: var self = this or claiming TypeScript changes binding.

intermediate2 min read

What is the purpose of the implements keyword?

Tests compile-time contract enforcement in TypeScript. Explain that implements checks class-to-interface compatibility at compile time with no runtime overhead, then code a CacheService with get and set methods.

intermediate2 min read

Strategies to type querySelector results as HTMLInputElement

Tests whether you know safe ways to narrow querySelector's Element or null to HTMLInputElement. A strong answer compares type assertions with generic querySelector calls, and insists on null checks. Red flag: asserting without runtime validation.

intermediate2 min read

How do you type-safely check an LI click and read data-id?

Tests TypeScript narrowing with DOM event delegation. A strong answer uses closest to walk up from event.target, checks result with instanceof HTMLLIElement, then reads dataset.id. Red flag: casting event.target directly without handling nested child elements.

Programmatically create and append a div in TypeScript
intermediate2 min read

Programmatically create and append a div in TypeScript

Tests TypeScript DOM typing and safe element creation. Strong answers name HTMLDivElement and Document, use createElement plus classList.add and textContent, then append. Red flag: innerHTML for text or avoiding specific types.

intermediate1 min read

Promise .catch() versus async/await try...catch

.catch() handles rejection for all preceding chain steps and reads functionally; try/catch reads synchronously and can scope errors per await, but only catches awaited rejections.

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