Skip to content
TryHired.
Interview prep · Technical · Node.js 24.15.0 type stripping

TypeScript interview questions: answers with real output

The type system questions front-end and full-stack developers get, answered in plain words, with examples run in Node.js to show what happens at runtime.

Updated Nov 15, 2026 · Examples run with Node.js 24.15.0 type stripping · questions: TryHired
Quick answer

TypeScript interviews test the type system and how it relates to the JavaScript that runs: types are erased at runtime, any versus unknown, interfaces versus type aliases, narrowing with typeof, in and instanceof, discriminated unions and exhaustive checks, generics, utility types, structural typing, satisfies, enums, keyof and conditional types, and private fields. Below are 14 questions; 12 examples were run and show real runtime output, and every statement about the type checker was checked against the TypeScript Handbook.

How the examples run

Runtime output, not compiler output

Advice

The examples were run with Node.js's built-in type stripping: Node.js removes the TypeScript syntax and runs the rest as JavaScript, without checking types. So the outputs show what the code does when it runs; none of them is a compiler error. To see the type errors the answers describe, run the same code through tsc --noEmit or an editor with TypeScript support.

Basic

Basic TypeScript interview questions

Advice

Basic1. Do TypeScript types exist at runtime?

No. Types are erased when TypeScript is compiled (or, as on this page, stripped by Node.js), so the running JavaScript has no idea what you annotated. A type assertion such as value as number only changes what the checker believes; it does not convert or check anything. Validate untrusted data (API responses, JSON, user input) at runtime yourself, for example with a type guard or a schema library.

TypeScript
const input: unknown = JSON.parse('{"price": "19.99"}');
const price = (input as { price: number }).price;
console.log(typeof price, price);
console.log(price + 1);
Output (Node.js 24.15.0 type stripping)
string 19.99
19.991

Checked against: Node.js docs: TypeScript type stripping, TypeScript Handbook: everyday types

Basic2. What is the difference between any and unknown?

Both accept any value. any switches type checking off, so you can call or read anything and mistakes surface only at runtime. unknown is the safe version: the checker will not let you use the value until you narrow it, for example with typeof. Prefer unknown for data whose shape you have not checked yet.

TypeScript
function describe(value: unknown): string {
  if (typeof value === 'string') return `string of length ${value.length}`;
  if (typeof value === 'number') return `number ${value.toFixed(2)}`;
  if (Array.isArray(value)) return `array of ${value.length}`;
  return 'something else';
}
for (const v of ['hi', 3.14159, [1, 2, 3], null]) console.log(describe(v));
Output (Node.js 24.15.0 type stripping)
string of length 2
number 3.14
array of 3
something else

Checked against: TypeScript Handbook: everyday types, TypeScript Handbook: more on functions

Basic3. What is the difference between an interface and a type alias?

For object shapes they are mostly interchangeable. The main difference: an interface can be reopened, so declaring it twice merges the members (declaration merging), which libraries use to let you extend their types; a type alias cannot be reopened. Type aliases can also name unions, tuples and other types that interfaces cannot describe, such as type Status = 'open' | 'closed'. Many teams use interfaces for object shapes and type aliases for everything else.

Checked against: TypeScript Handbook: everyday types

Basic4. How does narrowing work with typeof, in and instanceof?

Inside a branch guarded by a runtime check, TypeScript narrows the variable to the matching type: typeof for primitives, in for checking whether a property exists, instanceof for class instances. The checks themselves are ordinary JavaScript, which is why the example below prints a result for every input.

TypeScript
class ApiError extends Error { status: number; constructor(status: number) { super('api'); this.status = status; } }
type Result = string | number | { error: string } | ApiError;
function explain(r: Result): string {
  if (typeof r === 'string') return 'text: ' + r.toUpperCase();
  if (typeof r === 'number') return 'number: ' + r.toFixed(1);
  if (r instanceof ApiError) return 'API error with status ' + r.status;
  if ('error' in r) return 'error object: ' + r.error;
  return 'unreachable';
}
for (const r of ['ok', 2.5, { error: 'timeout' }, new ApiError(503)]) console.log(explain(r));
Output (Node.js 24.15.0 type stripping)
text: OK
number: 2.5
error object: timeout
API error with status 503

Checked against: TypeScript Handbook: narrowing

Basic5. What are literal types and as const?

A literal type is a single value used as a type, such as 'GET' or 42; unions of literals ('GET' | 'POST') are a common way to model fixed options. as const makes an object or array readonly in the type system and keeps its values as literal types instead of widening them to string or number. It is also a popular alternative to enums. At runtime, as const does not freeze anything, as the example shows.

TypeScript
const ROLES = ['admin', 'editor', 'viewer'] as const;
type Role = typeof ROLES[number];
function isRole(x: string): x is Role { return (ROLES as readonly string[]).includes(x); }
console.log(isRole('editor'), isRole('owner'));
(ROLES as unknown as string[]).push('owner');
console.log(ROLES);
Output (Node.js 24.15.0 type stripping)
true false
[ 'admin', 'editor', 'viewer', 'owner' ]

Checked against: TypeScript Handbook: everyday types

Intermediate

Intermediate TypeScript interview questions

Advice

Intermediate6. What is a discriminated union, and how do you make a switch exhaustive?

Give each member of a union a common literal property (the discriminant, here kind); checking it narrows to one member. In the default branch, assigning the value to never makes the compiler fail if someone adds a new member and forgets a case. Because types are erased, keep a runtime throw there too: data from outside can still contain a kind you did not expect.

TypeScript
type Shape = { kind: 'circle'; r: number } | { kind: 'square'; side: number };
function area(s: Shape): number {
  switch (s.kind) {
    case 'circle': return Math.PI * s.r ** 2;
    case 'square': return s.side ** 2;
    default: { const unreachable: never = s; throw new Error('unknown shape: ' + JSON.stringify(unreachable)); }
  }
}
console.log(area({ kind: 'circle', r: 1 }).toFixed(4), area({ kind: 'square', side: 3 }));
try { area(JSON.parse('{"kind": "triangle"}')); } catch (e) { console.log((e as Error).message); }
Output (Node.js 24.15.0 type stripping)
3.1416 9
unknown shape: {"kind":"triangle"}

Checked against: TypeScript Handbook: narrowing

Intermediate7. What are generics, and why not just use any?

A generic function takes a type parameter, so the type of what comes out depends on what goes in: first<T>(items: T[]) returns a T, so callers keep full type information. With any, the result is any and the checker stops helping. Constraints such as T extends { id: number } let the function use properties of T while staying generic.

TypeScript
function first<T>(items: T[]): T | undefined { return items[0]; }
function byId<T extends { id: number }>(items: T[], id: number): T | undefined { return items.find(i => i.id === id); }
console.log(first([10, 20, 30]), first(['a', 'b']), first([]));
console.log(byId([{ id: 1, name: 'Ava' }, { id: 2, name: 'Ben' }], 2));
Output (Node.js 24.15.0 type stripping)
10 a undefined
{ id: 2, name: 'Ben' }

Checked against: TypeScript Handbook: generics

Intermediate8. Which utility types do you use, and what does Readonly actually protect?

Partial makes every property optional (useful for patch updates), Pick and Omit build a type from a subset of another's properties, Record maps keys to a value type, and Readonly marks properties as not reassignable. Readonly is only a compile-time check: at runtime the object can still be changed unless you also freeze it, as the example shows.

TypeScript
type User = { id: number; name: string; email: string };
function update(u: User, patch: Partial<Omit<User, 'id'>>): User { return { ...u, ...patch }; }
const ava: Readonly<User> = { id: 1, name: 'Ava', email: 'ava@example.com' };
console.log(update(ava, { email: 'ava@work.example' }));
(ava as User).name = 'changed at runtime';
console.log(ava.name);
const frozen = Object.freeze({ ...ava });
(function () { 'use strict'; try { (frozen as User).name = 'x'; } catch (e) { console.log('strict mode:', (e as Error).constructor.name); } })();
console.log(frozen.name);
Output (Node.js 24.15.0 type stripping)
{ id: 1, name: 'Ava', email: 'ava@work.example' }
changed at runtime
strict mode: TypeError
changed at runtime

Checked against: TypeScript Handbook: utility types

Intermediate9. What does structural typing mean in TypeScript?

Types are compatible when their shapes match, not because of their names or declared relationships. Any object with the required properties is accepted, even an instance of an unrelated class. The exception people trip over is excess property checking: an object literal written directly into a typed position may not have extra properties, while the same object passed through a variable is fine.

TypeScript
interface Named { name: string }
class Product { name: string; price: number; constructor(name: string, price: number) { this.name = name; this.price = price; } }
function greet(x: Named) { return 'Hello, ' + x.name; }
const p = new Product('Desk', 250);
console.log(greet(p));
const withExtra = { name: 'Ava', team: 'Data' };
console.log(greet(withExtra));
Output (Node.js 24.15.0 type stripping)
Hello, Desk
Hello, Ava

Checked against: TypeScript Handbook: type compatibility

Intermediate10. What is the satisfies operator for?

x satisfies T checks that a value matches a type without changing the value's own inferred type. Compare annotating const config: Record<string, string | number>, which forgets which keys exist and which are numbers, with satisfies, which validates the object and keeps the exact keys and value types. At runtime it disappears entirely.

TypeScript
type Config = Record<string, string | number>;
const config = { host: 'localhost', port: 8080 } satisfies Config;
console.log(config.port + 1, config.host.toUpperCase());
Output (Node.js 24.15.0 type stripping)
8081 LOCALHOST

Checked against: TypeScript 4.9 release notes

Intermediate11. Should you use enums?

Enums are one of the few TypeScript features that generate JavaScript: an enum becomes a real object at runtime, and numeric enums also map numbers back to names. Because of that, tools that only strip types reject them; Node.js's built-in type stripping is one example. Many codebases use a const object with as const, or a union of string literals, instead. Know both, and match the style of the codebase.

TypeScript
const Status = { Open: 'open', Closed: 'closed' } as const;
type Status = typeof Status[keyof typeof Status];
function label(s: Status) { return s === Status.Open ? 'Still open' : 'Done'; }
console.log(Object.values(Status), label(Status.Closed));
Output (Node.js 24.15.0 type stripping)
[ 'open', 'closed' ] Done

Checked against: Node.js docs: TypeScript type stripping, TypeScript Handbook: enums

Advanced

Advanced TypeScript interview questions

Advice

Advanced12. What do keyof and indexed access types do?

keyof T is the union of T's property names, and T[K] is the type of property K. Together they let you write a getter that only accepts real keys and returns the right type for each, so get(user, 'age') is a number and get(user, 'agee') does not compile.

TypeScript
function get<T, K extends keyof T>(obj: T, key: K): T[K] { return obj[key]; }
const user = { name: 'Ava', age: 31 };
console.log(get(user, 'name'), get(user, 'age') + 1);
console.log(Object.keys(user));
Output (Node.js 24.15.0 type stripping)
Ava 32
[ 'name', 'age' ]

Checked against: TypeScript Handbook: keyof type operator

Advanced13. What are conditional types, and where would you use one?

A conditional type picks one of two types depending on whether one type is assignable to another, written A extends B ? X : Y. They power many built-in utilities (Exclude, Extract, ReturnType, NonNullable). With infer you can pull a type out of another, for example the element type of an array or the resolved type of a Promise. They exist only at compile time, so there is nothing to run here; be ready to write one such as type ElementOf<T> = T extends (infer U)[] ? U : never.

Checked against: TypeScript Handbook: conditional types

Advanced14. What is the difference between private and #private class fields?

TypeScript's private keyword is checked only by the compiler: after type stripping or compilation the property is an ordinary property, reachable with bracket notation or from plain JavaScript. A JavaScript private field (#name) is enforced by the runtime itself and is not visible from outside the class at all. Use # when privacy has to hold at runtime.

TypeScript
class Account {
  private pin = 1234;
  #secret = 'hidden';
  hasSecret() { return this.#secret.length > 0; }
}
const a = new Account();
console.log((a as any)['pin']);
console.log(Object.keys(a), (a as any)['#secret'], a.hasSecret());
Output (Node.js 24.15.0 type stripping)
1234
[ 'pin' ] undefined true

Checked against: TypeScript Handbook: classes

Practice

How to practice with this page

Advice
  • Predict each output, then explain which parts of the code the type checker sees and which parts run.
  • For every type-level answer, write one line that the compiler would reject.
  • Turn on strict mode in a small project and fix the errors it reports.
  • Review JavaScript runtime topics too: closures, this, promises and the event loop.
Next

Related interview prep and tools

Disclosure: TryHired makes HIRED, a paid job-search program, so we have a conflict of interest when we mention it. This question bank is free, with no TryHired signup.

FAQ

Questions people ask

What TypeScript topics come up often in interviews?
any versus unknown, interfaces versus type aliases, narrowing and type guards, generics with constraints, utility types, discriminated unions with exhaustive checks, and, for senior roles, conditional and mapped types, tsconfig strictness options and typing third-party JavaScript.
How did you run TypeScript without the compiler?
With Node.js's built-in type stripping, which removes type annotations and runs the result. It does not type-check, so the outputs here show what the code does at runtime. Run tsc --noEmit (or your editor) to see the type errors the answers describe.
Should I learn JavaScript before TypeScript for interviews?
Yes, or at the same time: TypeScript interviews still ask how the code behaves at runtime (closures, the event loop, this, promises), because the types disappear when it runs.
Method

How this page is built

TryHired wrote these questions and answers. Every code block on this page was run with Node.js type stripping (Node.js 24.15.0 type stripping) when the page was built (2026-11-15). Type stripping removes the TypeScript syntax and runs the remaining JavaScript without checking types, so the output shows runtime behavior only; statements about what the type checker accepts or rejects were checked against the TypeScript Handbook. The output shown is the real output, and the build stops if any example fails. The question list is general practice: it does not predict what a particular employer will ask.

What this page can't tell you
  • Interviewers ask different questions for different roles and levels.
  • Answers are short explanations, not complete references.
  • Node.js type stripping does not support TypeScript features that generate JavaScript (enums, namespaces with code, parameter properties), so the examples avoid them; the enum question explains the difference instead.
Sources
  1. Node.js docs: TypeScript type stripping (read 2026-11-15)
  2. TypeScript 4.9 release notes (read 2026-11-15)
  3. TypeScript Handbook: classes (read 2026-11-15)
  4. TypeScript Handbook: type compatibility (read 2026-11-15)
  5. TypeScript Handbook: conditional types (read 2026-11-15)
  6. TypeScript Handbook: enums (read 2026-11-15)
  7. TypeScript Handbook: everyday types (read 2026-11-15)
  8. TypeScript Handbook: more on functions (read 2026-11-15)
  9. TypeScript Handbook: generics (read 2026-11-15)
  10. TypeScript Handbook: keyof type operator (read 2026-11-15)
  11. TypeScript Handbook: narrowing (read 2026-11-15)
  12. TypeScript Handbook: utility types (read 2026-11-15)