TypeScript interviews test whether you understand structural typing, the difference between any and unknown, and that types disappear at runtime. Be ready to narrow a union, write a small generic pick, and explain never in exhaustive switch statements. Framework trivia is secondary.
This TypeScript cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.
Quick reference
- Structural: If it has the required fields, it matches — no nominal
implementsrequired (though you can). - any: Disables checking. Contagious. Avoid on public APIs.
- unknown: Must narrow. The safe top type for untrusted JSON.
- never: Values that cannot exist. Exhaustive checks assign leftover unions to
never. - Erase: Interfaces, generics, and types are compile-time.
typeofoperator in JS is runtime. - Narrow:
typeof,in, equality on a discriminant, type predicatesis. - interface vs type: Merging vs unions — give one example of each.
- satisfies: Check a value against a type without widening (TS 4.9+).
Copy-paste examples
Exhaustiveness with never
If you add a status and forget a case, assertNever fails typecheck.
type Status = 'open' | 'closed';
function assertNever(x: never): never {
throw new Error('Unexpected ' + x);
}
export function label(s: Status): string {
switch (s) {
case 'open':
return 'Open';
case 'closed':
return 'Closed';
default:
return assertNever(s);
}
}Common mistakes
- Saying TypeScript is a runtime validator like Zod (unless you added Zod).
- Cannot explain why
as Useron JSON is a lie. - Using
enumwithout knowing it emits JS objects (unlessas constunion). - Claiming
interfaceis faster at runtime — there is no runtime.
FAQ
- Is TypeScript object-oriented? It supports classes and interfaces, and also functional styles. Structural typing is the key difference from Java’s nominal types.
- What is declaration merging? Multiple
interfacewith the same name combine. Useful for patching libs; surprising in app code.
- How do you type BLOGPH0 extras? An
interface Window { analytics?: ... }in a.d.ts. Do notas anythe whole window.
Related TypeScript cheat sheets
Build with this stack
When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.
Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.