TOPIC-WISE INTERVIEW PRACTICE

TypeScript interview questions and quick answers

Types, interfaces, generics and safe patterns for real codebases.

Review 628 questions and short answers on TypeScript. Start with real examples below, then search, practise and follow links to full explanations.

628 questionsFree revision22 topics
START HERE

TypeScript: questions worth revising first

These answers come from AI Tapri's existing question bank and published interview guides. Open each answer and read the linked in-depth guide for examples and context.

01How do you get the element type of an array type or a tuple in TypeScript?

Use an indexed access with number: T[number]. For string[] it gives string, and for a readonly tuple declared as const it gives the union of its member literals.

Read the full explanation
02What is an assertion function in TypeScript?

An assertion function has a return type like asserts x is string. If it returns normally, TypeScript narrows x for the rest of the scope; if the check fails it must throw. It works like a guard that replaces an if block.

Read the full explanation
03What is the Awaited utility type for?

Awaited<T> gives the type you get after awaiting a promise, unwrapping nested promises too. Awaited<Promise<string>> is string. It is mostly used with ReturnType to get the resolved type of an async function.

Read the full explanation
04What is a conditional type in TypeScript?

A conditional type picks one of two types based on a check: T extends U ? X : Y. If T is assignable to U the result is X, otherwise Y. It lets types make decisions, like an if statement for types.

Read the full explanation
05What is a discriminated union and why is it useful?

A discriminated union is a union of object types that share a literal-typed property, such as kind or type. Checking that property narrows the whole object to one member, so each branch sees only the fields that belong to it.

Read the full explanation
06What is a distributive conditional type?

When a conditional type is applied to a naked type parameter that is a union, it runs once per union member and joins the results. IsString<string | number> becomes IsString<string> | IsString<number>. Wrapping in [T] turns this off.

Read the full explanation
07How would you explain "How do you get the element type of an array type or a tuple in TypeScript" in an interview?

"T[number] is the element type of any array-like type. With a const-asserted array, (typeof list)[number] gives the union of its literal members, so one array drives both runtime values and the type, without an enum."

Read the full explanation
08How would you explain "How do you get the element type of an array type or a tuple in TypeScript" to a beginner?

An array type says "a list of something". To get that "something" you ask for the type at any numeric index: T[number]. Combine this with as const and a list of strings turns into a type with exactly those strings. One list then serves both the runtime loop and the type.

Read the full explanation
YOUR PRACTICE SPACE

Find your next answer.

Pick a topic, search a keyword, or open a question to reveal the answer.

628 questions available
TYPESCRIPT

TypeScript quick answers

Showing 18 of 628
610 remaining

Free to practise. No account needed. Made for quick revision, not rote memorisation.

Keep preparing for TypeScript

Quick answers help with recall; detailed guides explain the reasoning, examples and common mistakes behind each answer.

More topics to practise