learn
TypeScript

Cheat sheet and 30-second answers

One page of ready-to-say answers for the night before.

Thirty seconds each, out loud, no notes. If any answer wobbles, follow its link back to the full page.

Core

Question30-second answer
Why TypeScript?Catches typos and bad refactors at compile time; types erase at emit. (why)
Checking vs emit?Independent — errors still emit; runtime sees plain JavaScript. (how)
Structural typing?Same shape means compatible, whatever the name. (how)
Node and .ts files?Strips types without checking; on by default, stable since 24.12.0. (how)
TypeScript 7?Native Go compiler since July 2026; API users stay on the 6.x line. (why)
interface vs type?Interfaces for object shapes; aliases for unions and compositions. (objects)
Excess property check?Fresh literals may only list known fields. (objects)
any vs unknown?any silences, unknown forces a guard — prefer guards. (any)
as vs guard?Assertions claim, guards prove; satisfies checks without widening. (any)
Narrowing tools?typeof, in, instanceof, literal equality, custom is. (unions)
Discriminated union?One shared literal field; each branch knows its shape. (unions)
Generics in one line?Placeholders the caller fills per call, inferred first. (generics)
Enum vs string union?Unions erase and match text; enums emit runtime objects. (enums)

Types at work

Question30-second answer
Partial / Pick / Omit?Derive optional, subset, and remainder shapes from one source. (utils)
keyof and typeof?List keys, borrow a value's type, index one field out. (utils)
private / readonly?Editor promises only — the emit ignores them. (classes)
.d.ts files?Shape promises for plain JavaScript; @types when the lib ships none. (modules)
import type?Type-only meaning; bundlers drop it, Node strips it. (modules)
strict enables?Null checks, no silent any, init checks — one switch, a family. (tsconfig)
target vs lib?Emit level versus available built-ins; independent knobs. (tsconfig)
Typing fetch?Generic envelope plus a runtime guard at the network edge. (react)
Migration order?checkJs, JSDoc, rename one file, tighten strictness last. (migrating)
When not to use it?Throwaways and tiny static pages; never as proof of correctness. (pros)

References

On this page