TypeScript interview questions and answers for TypeScript 7
18 TypeScript interview questions with tested answers: unknown vs any, narrowing, discriminated unions, generics, satisfies, branded types and TypeScript 7.
Updated 8 min read

In this article
This guide prepares you for the TypeScript questions asked in front-end, Node.js and full-stack interviews in 2026. You will be able to explain unknown versus any, model data with discriminated unions, write a generic that interviewers actually like, use satisfies correctly, and say what changed in TypeScript 6.0 and 7.0.
TypeScript 7.0, the native compiler rewritten in Go, was released on 8 July 2026, after TypeScript 6.0 in March. Every code sample below was type-checked with TypeScript 7.0.2, and the answers were checked against the TypeScript handbook and the official release announcements.

Beginner questions: the type system basics
1. What is TypeScript, and what does it do at runtime?
TypeScript is JavaScript with a static type system. The compiler checks types and then emits plain JavaScript with the types removed, so types have no effect at runtime: they cannot validate an API response or user input on their own. That is why real projects pair TypeScript with runtime validation at system boundaries.
2. What is the difference between any, unknown and never?
anyswitches type checking off for that value; anything goes, including mistakes.unknownaccepts any value but lets you do nothing with it until you narrow it, which makes it the safe type for untrusted input.neveris the type with no values: a function that always throws, or a branch that cannot be reached.
function len(x: unknown): number {
if (typeof x === "string") return x.length;
if (Array.isArray(x)) return x.length;
return 0;
}3. type or interface: which should you use?
Both describe object shapes, and for most objects either works. Differences worth naming: interfaces can be extended with extends and merge when declared twice (useful for augmenting library types); type aliases can name unions, tuples, primitives and computed types such as mapped and conditional types. Many teams use interface for public object contracts and type for everything else; consistency matters more than the choice.
4. What is narrowing?
Narrowing is how the compiler refines a broad type to a more specific one inside a branch, based on checks such as typeof, instanceof, in, equality, truthiness and Array.isArray. It is the reason unknown and union types are usable without casts.
5. What does strict do, and is it on by default?
strict enables a family of checks including strictNullChecks and noImplicitAny. Since TypeScript 6.0 it is on by default; you must set "strict": false to opt out. With it on, map.get(key) returns V | undefined, so you have to handle the missing case, which catches a large class of bugs.
Intermediate questions: modelling real data
6. What is a discriminated union, and how do you make a switch exhaustive?
A union of object types that share a literal "tag" property. Checking the tag narrows to one member. Assigning the leftover value to never in the default branch makes the compiler fail when someone adds a new member and forgets to handle it.
type Shape =
| { kind: "circle"; radius: number }
| { kind: "square"; size: number };
function area(s: Shape): number {
switch (s.kind) {
case "circle": return Math.PI * s.radius ** 2;
case "square": return s.size ** 2;
default: {
const unreachable: never = s; // error if a case is missing
return unreachable;
}
}
}7. Write a type-safe getProp function.
Use a generic constrained with keyof and an indexed access type for the return value:
function getProp<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
const id: number = getProp({ id: 1, name: "Asha" }, "id");
// getProp(user, "email") is a compile-time errorInterviewers look for the constraint (K extends keyof T) and the precise return type rather than any.
8. Which utility types do you use most?
Partial<T> (all optional, for patches), Required<T>, Readonly<T>, Pick<T, K> and Omit<T, K> (select or drop keys), Record<K, V> (dictionary types), ReturnType<F>, Parameters<F>, NonNullable<T> and Awaited<T>. A good example: type UserPatch = Partial<Omit<User, "id">> for an update endpoint that must not change the id.
9. What does satisfies do, and how is it different from a type annotation?
satisfies checks that a value matches a type without widening the value's own inferred type. An annotation replaces the inferred type with the declared one.
const routes = {
home: "/",
post: "/posts/:slug",
} satisfies Record<string, `/${string}`>;
routes.home; // type "/" is kept
// routes.typo // error: property does not existWith const routes: Record<string, string> instead, routes.typo would compile and be typed as string.
10. What do as const and type assertions do?
as const infers the narrowest literal, read-only type, which is handy for deriving unions from data: const levels = ["debug", "info", "warn"] as const; type Level = (typeof levels)[number];. A type assertion (value as User) tells the compiler to trust you; it performs no runtime check, so overusing it hides bugs. Prefer narrowing or a type guard.
11. What is a user-defined type guard?
A function whose return type is a type predicate such as v is string. When it returns true, the compiler narrows the argument in the calling code. A related tool is an assertion function, asserts v is NonNullable<T>, which narrows by throwing when the check fails.
function isString(v: unknown): v is string {
return typeof v === "string";
}
function assertDefined<T>(v: T): asserts v is NonNullable<T> {
if (v == null) throw new Error("missing");
}
Advanced questions: type-level programming and tooling
12. Explain conditional types and infer.
A conditional type chooses a type based on assignability: T extends U ? X : Y. Inside the condition, infer captures part of the matched type. Conditional types also distribute over unions when T is a naked type parameter.
type ElementOf<T> = T extends readonly (infer E)[] ? E : never;
type A = ElementOf<string[]>; // string13. What are mapped types and template literal types?
Mapped types build a new object type by iterating over keys ({ [K in keyof T]: ... }), optionally renaming them with as. Template literal types build string types. Together:
type Getters<T> = {
[K in keyof T as `get${Capitalize<string & K>}`]: () => T[K];
};
// Getters<{ id: number }> is { getId: () => number }14. What do NoInfer and const type parameters solve?
NoInfer<T> stops a parameter from contributing to inference, so in pick(options: T[], initial: NoInfer<T>) the call pick(["a", "b"], "c") is an error instead of widening T to include "c". A const type parameter (function first<const T extends readonly unknown[]>) infers literal types as if the caller had written as const.
15. Why do many teams avoid enum today?
Enums are one of the few TypeScript features that emit runtime code. Node.js now runs .ts files directly by stripping types, and that only works for erasable syntax; enums, namespaces with values and parameter properties are rejected. The erasableSyntaxOnly compiler option flags them. A union of string literals, or an as const object, gives the same safety with no runtime cost.
16. What changed in TypeScript 6.0 and 7.0?
TypeScript 6.0 (March 2026) was the last release built on the JavaScript codebase and prepared projects for the move: strict on by default, module defaulting to esnext, types defaulting to an empty array, rootDir defaulting to the directory containing tsconfig.json, and deprecations such as target: es5, moduleResolution: node (node10) and baseUrl. TypeScript 7.0 (July 2026) is the native Go port: the team reports 8x to 12x faster full builds, parallel type-checking, and a rebuilt language server. Options deprecated in 6.0 are now errors, and 7.0 has no stable programmatic API yet, so tools that embed the compiler (for example some framework template checkers) still use the @typescript/typescript6 compatibility package.
17. Does TypeScript check types when Node.js runs a .ts file?
No. Node.js strips types and runs the result without type-checking and ignores tsconfig.json. Run tsc --noEmit in CI (and in your editor) to catch type errors, and use verbatimModuleSyntax so type-only imports are written with import type.
18. TypeScript is structurally typed. What does that mean, and how do you get nominal-style types?
Compatibility is decided by shape, not by name: any object with the right properties is accepted, even if it was never declared as that type. That is flexible, but it means a UserId and an OrderId that are both string can be swapped by mistake. The common fix is a branded type, where an intersection with a unique marker property makes the two incompatible while staying a plain string at runtime:
type UserId = string & { readonly __brand: "UserId" };
const toUserId = (s: string) => s as UserId;
function loadUser(id: UserId) { /* ... */ }
loadUser(toUserId("u_42")); // ok
// loadUser("u_42"); // error: string is not UserIdWhat interviewers look for
- Safety over convenience:
unknowninstead ofany, narrowing instead of assertions. - Modelling skill: discriminated unions for states, utility types for variants of a model.
- Readable generics: constraints that explain intent, not puzzles.
- Awareness of the boundary: types vanish at runtime, so validate external data.
- Current tooling: strict by default, TypeScript 7's native compiler, Node's type stripping.
How to practise
- Install TypeScript with
npm install -D typescriptand runnpx tsc --noEmiton the snippets above. - Model a loading, success and error state as a discriminated union and render each case exhaustively.
- Rewrite one
any-heavy function from your own code withunknownand type guards. - Explain aloud the difference between
satisfiesand an annotation using the routes example.
Frequently asked questions
Which TypeScript version should I prepare for in 2026?
TypeScript 7.0, released on 8 July 2026, and the defaults introduced in 6.0. Type-checking results are meant to match 6.0 for code that compiles cleanly there, so the language questions are the same.
Is strict mode on by default now?
Yes. Since TypeScript 6.0
strictdefaults totrue. Set"strict": falseonly if you have a migration reason.Should I use type or interface?
Either works for object shapes. Use
typefor unions and computed types; interfaces add declaration merging andextends. Follow the codebase's convention.Does TypeScript validate API responses?
No. Types are erased at compile time. Validate untrusted data at runtime with explicit checks or a schema library, then let the compiler track the validated type.
Can Node.js run TypeScript without a build step?
Yes, for erasable syntax: Node.js strips types by default and the feature is stable in Node 24.12 and later. It does not type-check, and enums and parameter properties are not supported.
Is the tsgo command still needed?
No.
tsgocame from the preview package. TypeScript 7.0 installs the native compiler as the normaltscfrom thetypescriptpackage.
Your next customer could start right here.
Introduce your tool, product or business to readers exploring technology.
Explore placements and request a private quote
Sources
- Announcing TypeScript 7.0 — Microsoft TypeScript blog, 2026-07-08
- Announcing TypeScript 6.0 — Microsoft TypeScript blog, 2026-03-23
- Narrowing — TypeScript handbook
- Modules: TypeScript — Node.js documentation
- TypeScript blog — Microsoft
Written with substantial AI assistance. Facts checked against cited sources. Editorial policy.
Comments
No comments yet. Be the first to join the conversation.
Leave a comment
Every comment is read by a moderator before it appears. Your email address is never published; it is used only to contact you about this comment.
More from Cloudsoft Zone

Interview preparationInterview questions
Docker interview questions and answers for Docker Engine 29
18 Docker interview questions from images and volumes to build cache, Compose, networking, signals and the containerd image store, with short model answers.
By Cloudsoft Zone

Interview preparationInterview questions
PHP interview questions and answers for 2026 (PHP 8.4 and 8.5)
22 PHP interview questions grouped by level, with concise model answers and short examples covering strict types, enums, match, PDO, password hashing, property hooks and the PHP 8.5 pipe operator.
By Cloudsoft Zone

Resource guideResources
Free learning paths for web developers in 2026: freeCodeCamp, Odin Project, CS50
Six free, checked learning resources for aspiring web developers: freeCodeCamp, The Odin Project, CS50x, Full Stack Open, javascript.info and MIT OpenCourseWare, with what each teaches, what costs extra and how to combine them.
By Cloudsoft Zone
