mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-15 14:42:38 +03:00
19 lines
388 B
TypeScript
19 lines
388 B
TypeScript
export function invariant<T = unknown>(
|
|
condition: T,
|
|
errorMessage?: ((condition: T) => string) | string,
|
|
): asserts condition {
|
|
if (condition) {
|
|
return;
|
|
}
|
|
|
|
if (typeof errorMessage === 'undefined') {
|
|
throw new Error('Invariant failed');
|
|
}
|
|
|
|
if (typeof errorMessage === 'string') {
|
|
throw new Error(errorMessage);
|
|
}
|
|
|
|
throw new Error(errorMessage(condition));
|
|
}
|