Rule TypeScript

Discriminated Unions

Use discriminated unions for variant types instead of optional fields

typescripttypespatterns
CLAUDE.md

Use discriminated unions for variant types: { type: 'success', data: T } | { type: 'error', message: string } instead of { data?: T, message?: string }. The compiler enforces exhaustive handling.

Copy this block into your CLAUDE.md or agent config file to enforce it in your workflow.

get crystl