TypeScript Mapped Types: Transform Types Without Repetition
typescript
dev.to
The Repetition Problem // You have this type interface User { id: string; name: string; email: string; role: 'admin' | 'user'; } // You need these too interface UserUpdate { id?: string; // same fields, all optional name?: string; email?: string; role?: 'admin' | 'user'; } interface UserReadonly { readonly id: string; // same fields, all readonly readonly name: string; readonly email: string; readonly role: 'admin' | 'user'; } Three types, almo