Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/convex-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,15 @@ export type Equals<X, Y> =
* assert(x);
* // x is now of type string
* ```
* You can also provide a function, to avoid doing expensive string templating.
* @param arg A value to assert the truthiness of.
* @param message An optional message to throw if the value is not truthy.
* @param message An optional message to throw if the value is not truthy, or a function to generate the message.
*/
export function assert(value: unknown, message?: string): asserts value {
export function assert(
value: unknown,
message?: string | (() => string),
): asserts value {
if (!value) {
throw new Error(message);
throw new Error(typeof message === "function" ? message() : message);
}
}
Loading