aboutsummaryrefslogtreecommitdiff
path: root/utils/assert.ts
diff options
context:
space:
mode:
Diffstat (limited to 'utils/assert.ts')
-rw-r--r--utils/assert.ts36
1 files changed, 0 insertions, 36 deletions
diff --git a/utils/assert.ts b/utils/assert.ts
deleted file mode 100644
index 05de651..0000000
--- a/utils/assert.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * assert — throw if a condition is false, narrow the type otherwise.
- * For programmer errors (invariants that should never fail); use
- * Result<T, E> for recoverable failures.
- */
-export function assert(condition: unknown, message?: string): asserts condition {
- if (!condition) {
- throw new Error(message ?? 'Assertion failed')
- }
-}
-
-/**
- * Mark a branch as unreachable in an exhaustive switch. If the compiler
- * ever allows this to be reached, `value` stops being `never` and the
- * call site fails to type-check.
- *
- * Usage:
- * switch (kind) {
- * case 'a': ...
- * case 'b': ...
- * default: assertNever(kind)
- * }
- */
-export function assertNever(value: never, message?: string): never {
- throw new Error(message ?? `Unhandled case: ${String(value)}`)
-}
-
-/**
- * Throw if a value is null or undefined; return the narrowed value.
- */
-export function assertDefined<T>(value: T, message?: string): NonNullable<T> {
- if (value === null || value === undefined) {
- throw new Error(message ?? 'Expected value to be defined')
- }
- return value as NonNullable<T>
-}