Skip to content

Instantly share code, notes, and snippets.

@jonathanconway
Last active July 24, 2026 05:25
Show Gist options
  • Select an option

  • Save jonathanconway/d2578f0b37d72a5c14b6f03de51d671a to your computer and use it in GitHub Desktop.

Select an option

Save jonathanconway/d2578f0b37d72a5c14b6f03de51d671a to your computer and use it in GitHub Desktop.
Assertion helper function, to generate informative, type-safe assertions
export function assert(
condition: unknown,
message?: string
): asserts condition {
if (!condition) {
throw new AssertionViolationError(message);
}
}
export class AssertionViolationError extends Error {
override name = "AssertionViolation";
constructor(message?: string) {
super(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment