| name | typescript_advanced |
| description | TypeScript 5+ advanced patterns, type utilities ve best practices rehberi. |
📘 TypeScript Advanced
TypeScript 5+ advanced patterns rehberi.
📋 Utility Types
type PartialUser = Partial<User>;
type RequiredUser = Required<User>;
type UserName = Pick<User, 'id' | 'name'>;
type UserWithoutPassword = Omit<User, 'password'>;
type UserMap = Record<string, User>;
type Result = ReturnType<typeof fetchUser>;
🔧 Advanced Patterns
Discriminated Unions
type Result<T> =
| { success: true; data: T }
| { success: false; error: string };
function handle(result: Result<User>) {
if (result.success) {
console.log(result.data);
} else {
console.log(result.error);
}
}
Template Literal Types
type EventName = `on${Capitalize<string>}`;
type Route = `/${string}`;
Conditional Types
type NonNullable<T> = T extends null | undefined ? never : T;
type Flatten<T> = T extends Array<infer U> ? U : T;
🎯 Zod Integration
import { z } from 'zod';
const UserSchema = z.object({
id: z.string().uuid(),
email: z.string().email(),
age: z.number().min(0).max(120),
});
type User = z.infer<typeof UserSchema>;
⚡ Best Practices
- Strict mode always on
- Avoid
any - use unknown instead
- Prefer interfaces for objects
- Use const assertions for literals
- Type narrowing over type assertions
🔄 Workflow
Kaynak: TypeScript 5.0 Release Notes & Total TypeScript Best Practices
Aşama 1: Type Design & Schema
Aşama 2: Advanced Logic Implementation
Aşama 3: Refactoring & Verification
Kontrol Noktaları
| Aşama | Doğrulama |
|---|
| 1 | eslint-plugin-typescript hataları temizlendi mi? |
| 2 | "Discriminated Unions" ile tüm case'ler handle edildi mi? |
| 3 | Tip tanımları ile gerçek runtime verileri tutarlı mı? |
TypeScript Advanced v1.5 - With Workflow