Skip to main content
Deno 2 is finally here 🎉️
Learn more

What is invariant?

invariant is a basic Deno implementation of invariant.

Usage

async function fetchSomething(id?: string): Promise<Response> {
  // tsc knows id is either string | undefined
  invariant(
    typeof id === "string",
    `Unable to fetch something, bad Id: "${String(id)}"`,
  );
  // tsc knows id is string or an error is throw
  return await fetch(`https://some-resource.dev/gimme/${id}`);
}