ClaudeTypeScript
Advanced TypeScript Type Builder
Why this prompt matters
Advanced TypeScript types replace runtime validation with compile-time guarantees, catching bugs before they reach production.
What we use it for
TypeScript
Prompt
Create TypeScript types for the described requirement. Use advanced features where appropriate: generics, conditional types, mapped types, template literal types, infer keyword. Include: 1) The type definition, 2) Usage examples, 3) What compile-time errors it catches, 4) Alternative approaches considered.
Result
```typescript
// Deep partial that makes all nested properties optional
type DeepPartial = T extends object ? {
[P in keyof T]?: DeepPartial;
} : T;
// Type-safe event emitter
type EventMap = {
'user:created': { id: string; email: string };
'order:completed': { orderId: string; total: number };
};
type EventHandler = (payload: EventMap[K]) => void;
class TypedEmitter {
on(event: K, handler: EventHandler): void {}
emit(event: K, payload: EventMap[K]): void {}
}
```
**Catches**: Misspelled event names, wrong payload shapes, missing required fields.
Advanced TypeScript types replace runtime validation with compile-time guarantees, catching bugs before they reach production.
This prompt demonstrates a structured approach to typescript, producing consistent, high-quality results that can be iterated upon.