Skip to content
tezvyn:

TypeScript & Web APIs

TypeScript, browser APIs, WebAssembly, PWAs

32 bites

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

Easy interview questions in TypeScript & Web APIs

easy2 min read

Declare a string name and an array of lucky numbers in TypeScript

Declare the name with a lowercase string type and the lucky numbers as number[] or Array<number>.

easy2 min read

Explain what TypeScript's type inference is and show an inferred variable declaration

This tests whether you understand TypeScript deduces types without annotations. A strong answer defines inference as deriving types from values and gives an example like let x = 3 inferring number. A red flag is claiming explicit types are required.

What is the fundamental difference between window and document?
easy2 min read

What is the fundamental difference between window and document?

Window is the browser tab and global scope; document is the object-oriented DOM representation of the loaded page.

What happens when you declare var globally versus let or const?
easy2 min read

What happens when you declare var globally versus let or const?

Knowledge that var creates a Window property while let and const do not. A good answer notes var adds window.x, let/const do not pollute the global object, yet both are globally scoped.

How do you select by ID and class, and what is returned?
easy2 min read

How do you select by ID and class, and what is returned?

This tests basic DOM API knowledge and awareness of live collections. Use document.getElementById for IDs and document.getElementsByClassName for classes, which returns a live HTMLCollection. A red flag is calling the result a static Array or NodeList.

easy2 min read

Define a User object shape: interface vs type alias?

Tests structural typing and API contracts. Good answer: interface for API objects because it merges; type alias for unions. Forced: declaration merging needs interface; discriminated unions need type. Red flag: claiming performance differences.

easy2 min read

How do you type a function with two possible response shapes?

This checks TypeScript union types for API responses. Define a union of Product[] and a message object, use a type guard to narrow it at runtime, and return that.

easy2 min read

Type alias for a function with optional param and default value

Tests whether you know function type expressions cannot encode default values. A great answer writes (s: string, n?: number) => boolean, explains defaults are implementation-only, and notes parameter names are required.

easy2 min read

Create a Person class using TypeScript parameter properties

This tests TypeScript parameter properties: constructor access modifiers auto-declare and initialize fields. A strong answer gives class Person { constructor(public name: string, private age: number) {} } and notes it removes manual this.name = name…

easy2 min read

What is getElementById's return type and the check needed for .value?

Tests strict null awareness: getElementById returns HTMLElement or null, so null-check first. Strong answers note HTMLElement lacks .value, requiring narrowing to HTMLInputElement. Red flag: assuming a valid element is always returned.

What is the click event's type and how to reference the button?
easy2 min read

What is the click event's type and how to reference the button?

Handler receives a MouseEvent. Use event.currentTarget for the attached button, since event.target may be a nested child.

How do you wrap a callback-based API into a Promise?
easy2 min read

How do you wrap a callback-based API into a Promise?

This tests Promise constructor mechanics and callback migration. A strong answer returns a new Promise, calls the legacy function, maps success to resolve and errors to reject.

Write a fetch call and log JSON from the Response
easy2 min read

Write a fetch call and log JSON from the Response

This tests async HTTP literacy and fetch's two-stage promise resolution. A strong answer awaits fetch, then awaits response.json(), logs result, and notes fetch does not throw on 4xx/5xx.

How would you modify fetch to handle HTTP error statuses?
easy2 min read

How would you modify fetch to handle HTTP error statuses?

Verify response.ok in then and throw if false, then catch network failures separately.

Write a createUser function that POSTs JSON via fetch
easy2 min read

Write a createUser function that POSTs JSON via fetch

Precise fetch configuration for JSON POST requests. A strong answer names method POST, headers Content-Type application/json, and body JSON.stringify(data) with return typing. Red flag: passing the raw object as body or omitting headers.

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.

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

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

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

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.

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