Files
Desktop/ts/axo/_internal/assert.dom.tsx
Fedor Indutny 44076ece79 Rename files
2025-10-16 23:45:44 -07:00

24 lines
730 B
TypeScript

// Copyright 2025 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export class AssertionError extends TypeError {
override name = 'AssertionError';
}
export function assert(condition: boolean, message?: string): asserts condition;
export function assert<T>(input: T, message?: string): NonNullable<T>;
export function assert<T>(input: T, message?: string): NonNullable<T> {
if (input === false || input == null) {
// eslint-disable-next-line no-debugger
debugger;
throw new AssertionError(message ?? `input is ${input}`);
}
return input;
}
export function unreachable(_value: never): never {
// eslint-disable-next-line no-debugger
debugger;
throw new AssertionError('unreachable');
}