typescript-impossible-states-mining
Mine TypeScript types that make illegal states representable
# typescript-impossible-states-mining
For background on this miner, see this [blog post](https://codemod.com/blog/continuous-code-health-auditing-at-scale).
Read-only miner for TypeScript types that **make illegal states representable**. If you've ever shipped `isLoading && isError && data` on the same object, or a pile of `isAdmin` / `isOwner` / `canEdit` booleans that should have been a discriminated union, this is the scan.
It never edits source. Every hit is one `ts_impossible_state` metric row. Treat findings as review candidates, not a rewrite plan — a union or a `Map` may be the right fix, the miner cannot decide that.
## Metric
**Name:** `ts_impossible_state`
| Cardinality | Values |
| ------------- | --------------------------------------------------------- |
| `rule_id` | detector id |
| `category` | `state_representation`, `control_flow`, `collections` |
| `confidence` | `high`, `medium`, `low` (match-strength, not probability) |
| `file_path` | target-relative path |
| `line_number` | 1-based |
| `symbol` | type or enclosing function name |
| `details` | optional sorted `key=value` pairs (cap ~80 chars) |
## Catalog
| `rule_id` | Category | Confidence | What it matches |
| -------------------------- | ---------------------- | ---------- | ----------------------------------------------------------------------------------------------------------- |
| `boolean_flag_cluster` | `state_representation` | medium | ≥3 `is`/`has`/`can`/`should` boolean fields on one interface, type alias, or class |
| `async_status_triple` | `state_representation` | high | ≥2 of `{isLoading,isError,isSuccess,isIdle,isFetching,…}` plus `data`/`error`/`result` on the same type |
| `string_status_with_flags` | `state_representation` | medium | `status`/`state`/`kind`/`phase` typed as `string` or a string union **plus** boolean flags on the same type |
| `nested_linear_lookup` | `collections` | high | `.find` / `.findIndex` / `.filter`[0] inside `map` / `forEach` / `for` |
| `repeated_member_switch` | `control_flow` | low | ≥2 `switch` or if/else-if chains on the same member inside one function |
## What it ignores
- Independent HTML/ARIA booleans (`disabled`, `hidden`, `required`, `readOnly`)
- A single `isLoading` next to `data`
- A narrow `'idle' \| 'loading' \| 'error'` union with **no** extra flags
- Top-level `.find` and `Map.get` inside `map`
- One switch, or switches on different fields
- Cross-file duplicated shapes, abort/generation-counter bugs, module-boundary advice