Quick Reference · the type layer over ES2024 JavaScript

TS typescript cheat sheet

TypeScript is JavaScript plus a type layer that lives only at compile time. You annotate; tsc checks the shapes structurally, then erases every type — the JavaScript that runs is plain and typeless. Learn the type system and the tooling carries the rest.

tooling & config types & values interfaces & narrowing functions & generics classes & modules type-level & TS 7 most common

Synthesized & cross-checked against: typescriptlang.org Handbook · the four official cheat sheets (Types · Interfaces · Classes · Control Flow) · the TypeScript 7.0 release notes · MDN · TC39 · verified against tsc 7.0 (native)

The one idea: you write types → tsc checks them → they're erased
WHAT YOU WRITE WHAT SHIPS app.ts code + types interface · : string <T> · as · satisfies tsc type‑check structural · compile‑time shapes agree? erase types keep types app.js types gone · this is what runs runs on any JS engine app.d.ts the types, extracted for editors & consumers Types are a compile‑time layer. They never run — they cost nothing at runtime.

What’s new TypeScript 7.0 · native

7.0 is a performance release, not a syntax one — the whole sheet below is unchanged. It's the same type system, checked by a Go compiler roughly 10× faster.

10× faster · native Go

Project Corsa — a Go port of tsc. GA Jul 8 2026. A port, not a rewrite: type-checking is identical to 6.0. vscode 125.7s → 10.6s.

strict by default

strict:true, module:esnext, and target = the latest stable ES. Adopt 6.0's defaults before you jump.

removed for good

Hard errors now: target:es5, downlevelIteration, baseUrl, and node10/classic/amd/umd resolution.

parallel build flags

--checkers N (default 4) and --builders N tune parallelism; --singleThreaded turns it off for CI / debugging.

no API until 7.1

typescript-eslint and Vue / Svelte / Astro / Angular templates still need TS 6 — run it side-by-side as tsc6.

Unicode template types

Inferring `${infer H}${infer T}` now keeps 😀 whole instead of splitting the surrogate pair.

01Setup & Compiletypes → checked → erased
02Everyday Typeslet x: T
03Arrays, Tuples & Objectsshapes of data
04Unions, Literals & Enumsone of a set
05Interfaces & Type Aliasesname a shape
06Narrowing · Control Flowunion → one type
07Functionstyped in & out
08Genericstypes as parameters
09Classestyped OOP
10Decoratorsannotate classes
11keyof, typeof & Indexingtypes from values
12Mapped Typestransform each key
13Conditional & Template Typestype-level logic
14Utility Typesbuilt-in transforms
15Assertions & satisfiesoverride the checker
16Modules & Declarationsshare types across files
17Working Typesfrom lib.d.ts
18tsconfig EssentialscompilerOptions

Four ideas that unlock the rest

The type system is small once these click: what disappears at compile time, why shapes (not names) decide compatibility, how a union collapses to one type, and how utility types rewrite a shape.

1 · What survives compile

Almost everything type-related is erased. A handful of constructs emit real JavaScript — know which.

ERASED · compile-time only type · interface : type annotations generics <T> as · satisfies · ! readonly · private import type EMITTED · real JavaScript class enum namespace constructor(public x) #private fields so there's no x instanceof SomeInterface — it isn't there at runtime

2 · Structural (“duck”) typing

Compatibility is about shape, not name. Has the required members? It fits — no implements needed.

a value name: "Rex" age: 4 legs: 4 (extra — ignored) fits interface Named name: string age: number required shape but an object literal triggers an excess-property check on the extra

3 · Narrowing a union

Control-flow analysis: a guard splits string | number so each branch sees exactly one type.

string | number typeof x === "string" true false string .toUpperCase() number .toFixed(2)

4 · Utility types rewrite a shape

Built-in mapped types take a type and hand back a modified one — nothing is copied by hand.

User id: number name: string Partial<User> id? · name? Readonly<User> readonly id · name Pick<User, "id"> id: number  (name dropped)

Worth memorizing

interface vs typeinterfaces extend & merge; type does unions, tuples, mapped. Objects → interface, rest → type
as vs satisfiesas overrides (can lie); satisfies checks and keeps the narrow type
types are erasedno runtime type info — you can't instanceof an interface
any is contagiousit silently spreads and disables checks — reach for unknown
strictNullChecksnull/undefined must be handled — the single most valuable strict flag
excess-propertythe extra-key error only fires on object literals, not variables
structural typingsame shape ⇒ compatible; no implements required
enum emits codeprefer a literal union or as const; const enum inlines
readonly / privatecompile-time only (erased); #field is the real runtime private
optional ?:makes T | undefined — which is not the same as | null
! is a promisenon-null ! and as are unchecked — they can still crash
empty [] → any[]annotate arrays you'll fill later, or inference gives up
declaration mergingtwo same-name interfaces silently combine into one
TS 7 defaultsstrict on, esnext module; es5/baseUrl/node10 resolution are gone