Type Design Review
Use this as a focused review lens when a diff adds or changes data models,
function signatures, domain types, parsing/validation boundaries, casts, or
state machines.
The central question: what states does this type allow, and which of those does
the domain forbid? A permitted-but-forbidden state is a review finding when it
is realistically reachable, would cause a real bug or repeated defensive checks,
and can be prevented with a reasonably small type change.
Review Questions
Impossible states.
- Are mutually exclusive states modeled as independent booleans or optional
fields?
- Could success and error, loading and loaded, present and absent, or two
incompatible modes be represented at once?
- Would a tagged union, sum type, enum-with-data, or explicit state object
make the domain shape clearer?
Parse, do not merely validate.
- Does validation return
true, false, or void and then throw away the
proof?
- Can boundary input be parsed into a narrower type that callers carry
inward?
- Does the repo already use a parser/schema library that should be reused?
Primitive confusion.
- Are domain identifiers, units, currencies, paths, or statuses plain strings
or numbers that can be mixed up?
- Would a branded, opaque, wrapper, or language-native newtype prevent a real
class of mistakes?
Unsafe assertions and nullability.
- Did the diff add unchecked casts,
as any, non-null assertions, or
equivalent escape hatches?
- Is there a nearby runtime check, parser, or control-flow narrowing that
justifies the assertion?
Exhaustiveness.
- Do switches, matches, or conditionals over closed states fail at compile
time when a new state is added?
- If the language supports exhaustive matching, is the code using it?
Derived vs duplicated state.
- Are count, index, selected item, cache, or status fields stored separately
from the source that defines them?
- Can the code derive one from the other to remove desynchronization?
Proportionality
Do not add type ceremony for free text, throwaway locals, or combinations the
domain genuinely permits. The finding must name the invalid state it prevents.
If every represented state is valid, the type is already precise enough.
Do not recommend a new dependency just to satisfy this review. Prefer an
existing parser/schema tool when the repo already uses one; otherwise suggest a
small local constructor or guard.
Output
For each finding, include:
- smell: impossible state, lost parse proof, primitive confusion, unsafe
assertion, missing exhaustiveness, or duplicated state
- invalid state that is currently representable
- location
- concrete restructuring
- severity:
BLOCKER, SHOULD, or NIT
If the diff has no type-design issue, say that clearly and leave correctness,
simplicity, and test coverage to the general review workflow.
Source Note
Inspired by the type-design review lens in
lucasfcosta/backpressured,
adapted here as portable seam-driven workflow guidance.
1---2name: type-design-review3description: Use when reviewing data models, signatures, domain types, parsing, casts, or state machines so invalid states stay hard to represent.4---56# Type Design Review78Use this as a focused review lens when a diff adds or changes data models,9function signatures, domain types, parsing/validation boundaries, casts, or10state machines.1112The central question: what states does this type allow, and which of those does13the domain forbid? A permitted-but-forbidden state is a review finding when it14is realistically reachable, would cause a real bug or repeated defensive checks,15and can be prevented with a reasonably small type change.1617## Review Questions18191. **Impossible states.**20 - Are mutually exclusive states modeled as independent booleans or optional21 fields?22 - Could success and error, loading and loaded, present and absent, or two23 incompatible modes be represented at once?24 - Would a tagged union, sum type, enum-with-data, or explicit state object25 make the domain shape clearer?26272. **Parse, do not merely validate.**28 - Does validation return `true`, `false`, or `void` and then throw away the29 proof?30 - Can boundary input be parsed into a narrower type that callers carry31 inward?32 - Does the repo already use a parser/schema library that should be reused?33343. **Primitive confusion.**35 - Are domain identifiers, units, currencies, paths, or statuses plain strings36 or numbers that can be mixed up?37 - Would a branded, opaque, wrapper, or language-native newtype prevent a real38 class of mistakes?39404. **Unsafe assertions and nullability.**41 - Did the diff add unchecked casts, `as any`, non-null assertions, or42 equivalent escape hatches?43 - Is there a nearby runtime check, parser, or control-flow narrowing that44 justifies the assertion?45465. **Exhaustiveness.**47 - Do switches, matches, or conditionals over closed states fail at compile48 time when a new state is added?49 - If the language supports exhaustive matching, is the code using it?50516. **Derived vs duplicated state.**52 - Are count, index, selected item, cache, or status fields stored separately53 from the source that defines them?54 - Can the code derive one from the other to remove desynchronization?5556## Proportionality5758Do not add type ceremony for free text, throwaway locals, or combinations the59domain genuinely permits. The finding must name the invalid state it prevents.60If every represented state is valid, the type is already precise enough.6162Do not recommend a new dependency just to satisfy this review. Prefer an63existing parser/schema tool when the repo already uses one; otherwise suggest a64small local constructor or guard.6566## Output6768For each finding, include:6970- smell: impossible state, lost parse proof, primitive confusion, unsafe71 assertion, missing exhaustiveness, or duplicated state72- invalid state that is currently representable73- location74- concrete restructuring75- severity: `BLOCKER`, `SHOULD`, or `NIT`7677If the diff has no type-design issue, say that clearly and leave correctness,78simplicity, and test coverage to the general review workflow.7980## Source Note8182Inspired by the type-design review lens in83[lucasfcosta/backpressured](https://github.com/lucasfcosta/backpressured),84adapted here as portable seam-driven workflow guidance.