Typsicheres Superset von JavaScript.
TypeScript ist Microsofts typsicheres Superset von JavaScript — statische Typen werden zur Compile-Zeit geprüft und beim Build entfernt. Industriestandard für seriöse JS-Codebases, in dieser Codebase strict-mode default.
pnpm add -D typescript @types/node
pnpm tsc --init --strict
pnpm tsc --noEmit # Typecheck ohne Output
tsconfig.json mit "strict": true, "noUncheckedIndexedAccess": true und "moduleResolution": "bundler" für Next/Vite.
type Result<T> = { ok: true; value: T } | { ok: false; error: string }
satisfies statt Type-Annotation, wenn Inference erhalten bleiben soll:
const config = { port: 3000 } satisfies Config
z.infer<> für Typen aus Schema.`on${Capitalize<K>}`.as const für readonly tuples und literal-narrowing.any ist ansteckend — einmal drin, frisst es die Typsicherheit ganzer Call-Chains. unknown + Type-Guard nutzen.Object.keys(obj) gibt string[] zurück, nicht (keyof T)[] — bewusste Type-Assertion nötig.noUncheckedIndexedAccess macht arr[0] zu T | undefined — viele Codebases vergessen das initial.as const-Objects.instanceof funktioniert nur bei Klassen.Wegwerf-Prototypen oder 50-Zeilen-Skripte. Aber selbst dort lohnt JSDoc-Types mit // @ts-check.