TypeScript adds types to JavaScript. It catches errors at compile time and improves DX. Today it’s the standard for serious projects.
Basic Types¶
// Primitive types 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” } }
Key Takeaway¶
strict: true from the start. Interface for objects, type for unions. Generics for reusable code.