Skip to content

Commit 3f55607

Browse files
committed
docs(types): clarify usage of 'satisfies never' over 'const _exhaustive' in exhaustive checks
1 parent b7370ad commit 3f55607

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

.agents/skills/typescript/SKILL.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,22 @@ switch (error.name) {
420420
}
421421
```
422422

423-
Why `satisfies never` and not the older `const _exhaustive: never = error; void _exhaustive;` dance: the unused-variable suppression is brittle (depends on lint config), and `satisfies never` is the idiom TypeScript 4.9+ blesses. Same compile-time guarantee, no dead code at runtime.
423+
Why `satisfies never` and not `const _exhaustive: never = error; void _exhaustive;`? Same compile-time guarantee, less emit, no unused-variable suppression dance.
424+
425+
```typescript
426+
// satisfies — type-level only, strips to the bare expression
427+
default: error satisfies never;
428+
// emits: default: error;
429+
430+
// const form — declares a real binding, needs `void` to silence unused-var
431+
default: {
432+
const _exhaustive: never = error;
433+
void _exhaustive;
434+
}
435+
// emits: default: { const _exhaustive = error; void _exhaustive; }
436+
```
437+
438+
`satisfies` (TS 4.9+) is the blessed idiom for "assert conformance without producing a value."
424439

425440
**When NOT to add an exhaustive check:**
426441

0 commit comments

Comments
 (0)