@here.build/error-invariant
v0.9.0
Published
Global Error.invariant assertion helper (augments ErrorConstructor; TypeError.invariant resolves via constructor prototype inheritance)
Readme
@here.build/error-invariant
A side-effect import that installs a global Error.invariant(condition, message) assertion helper.
Install
pnpm add @here.build/error-invariantUsage
Import once (for the side effect) — typically at an entry point:
import "@here.build/error-invariant";
Error.invariant(user != null, "user is required");
// throws an Error when the condition is falsy
TypeError.invariant(typeof x === "number", "x must be a number");
// throws a TypeError — the *receiver's* typeinvariant resolves on Error and every subclass via the constructor prototype chain, and throws an instance of the constructor it was called on (MyError.invariant(...) throws a MyError). When the condition holds, it narrows the type for the rest of the scope.
⚠️ Global side effect. Importing this package mutates the global
Errorconstructor (and its subclasses). That is its entire purpose — do not configure your bundler to tree-shake the import away.
