Skip to content

Commit

Permalink
Add invariant method (#780)
Browse files Browse the repository at this point in the history
- Add invariant method to core.
  • Loading branch information
mattias800 committed Sep 4, 2024
1 parent 35768c7 commit 5545d16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ export * from "./utils/TruthyKeysAsList";
export * from "./utils/PropsForwarder";
export * from "./utils/parsers/NumberParser";
export { booleanOrNumberToNumber } from "./utils/BooleanOrNumberToNumber";
export * from "./utils/Invariant";
8 changes: 8 additions & 0 deletions packages/core/src/utils/Invariant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function invariant<T>(
val: T | null | undefined,
message: string
): asserts val is T {
if (val == null) {
throw new Error("Invariant error: " + message);
}
}

0 comments on commit 5545d16

Please sign in to comment.