aboutsummaryrefslogtreecommitdiff
path: root/utils/assert/assert.ts
blob: 1fd70c8d20cab47ffa129d40fadb7c9f1b9043ac (plain)
1
2
3
4
5
6
7
8
9
10
/**
 * Throw if a condition is false, narrow the type to truthy 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')
  }
}