# TypeScript Tips and Tricks TypeScript helps you write better code by catching errors early. Here are some advanced tips. ## 1. Use Strict Mode Enable `strict` mode in tsconfig.json: ```json { "compilerOptions": { "strict": true } } ``` ## 2. Discriminated Unions Use discriminated unions for type-safe state management: ```typescript type Result = | { status: 'success'; data: string } | { status: 'error'; error: Error } function handleResult(result: Result) { if (result.status === 'success') { console.log(result.data) } else { console.log(result.error) } } ``` ## 3. Generics Create reusable components: ```typescript function identity(arg: T): T { return arg } ``` ## 4. Type Guards Narrow types safely: ```typescript function isString(value: unknown): value is string { return typeof value === 'string' } ``` Keep learning and improve your TypeScript skills!