TypeScript přidává typy do JavaScriptu. Zachytí chyby při kompilaci, zlepší DX. Dnes standard pro seriózní projekty.
Základní typy¶
// Primitivní typy let name: string = ‘Jan’; let age: number = 30; let active: boolean = true; // Interface interface User { id: number; name: string; email: string; role?: ‘admin’ | ‘user’; // Optional + union } // Generics function first(items: T[]): T | undefined { return items[0]; } // Utility types type PartialUser = Partial; type UserWithoutId = Omit;
tsconfig.json¶
{ “compilerOptions”: { “target”: “ES2022”, “module”: “NodeNext”, “strict”: true, “noUncheckedIndexedAccess”: true, “outDir”: “dist” } }
Klíčový takeaway¶
strict: true od začátku. Interface pro objekty, type pro unie. Generics pro reusable kód.