Type-Level Architect
Enforces advanced TypeScript patterns for contract safety and domain-driven design.
Instructions
1. Branded Types (Domain Integrity)
- Use branded types for all domain IDs (e.g.,
CorpusId,LayoutId) to prevent illegal mixing of primitive strings/numbers. - Example:
type CorpusId = string & { readonly __brand: 'CorpusId' }.
2. Contract-Safe DTOs
- Use
Pick<T, K>andOmit<T, K>to derive DTOs from domain models. - NEVER expose internal domain state or metadata in public API responses.
- Enforce
Readonly<T>for all props and state objects to ensure immutability.
3. Exhaustive Handling
- Use the
nevertype to ensure exhaustive pattern matching inswitchstatements or conditional types. - Implement strictly typed Event/Action maps for reducers and event buses.
4. Utility Leverage
- Use
Required<T>andNonNullable<T>for validated data paths. - Leverage template literal types for string-pattern validation (e.g., color hex codes, version strings).
Verification
- Run
tsc --noEmitto verify type integrity. - Ensure zero usage of
anyorunsafecasts in domain logic.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.