| 1 | /**
|
|---|
| 2 | * Asserts that a given condition is true. If the condition is false, an error is thrown with the provided message.
|
|---|
| 3 | *
|
|---|
| 4 | * @param {unknown} condition - The condition to evaluate.
|
|---|
| 5 | * @param {string} message - The error message to throw if the condition is false.
|
|---|
| 6 | * @returns {void} Returns void if the condition is true.
|
|---|
| 7 | * @throws {Error} Throws an error if the condition is false.
|
|---|
| 8 | *
|
|---|
| 9 | * @example
|
|---|
| 10 | * // This call will succeed without any errors
|
|---|
| 11 | * invariant(true, 'This should not throw');
|
|---|
| 12 | *
|
|---|
| 13 | * // This call will fail and throw an error with the message 'This should throw'
|
|---|
| 14 | * invariant(false, 'This should throw');
|
|---|
| 15 | */
|
|---|
| 16 | declare function invariant(condition: unknown, message: string): asserts condition;
|
|---|
| 17 | /**
|
|---|
| 18 | * Asserts that a given condition is true. If the condition is false, an error is thrown with the provided error.
|
|---|
| 19 | *
|
|---|
| 20 | * @param {unknown} condition - The condition to evaluate.
|
|---|
| 21 | * @param {Error} error - The error to throw if the condition is false.
|
|---|
| 22 | * @returns {void} Returns void if the condition is true.
|
|---|
| 23 | * @throws {Error} Throws an error if the condition is false.
|
|---|
| 24 | *
|
|---|
| 25 | * @example
|
|---|
| 26 | * // This call will succeed without any errors
|
|---|
| 27 | * invariant(true, new Error('This should not throw'));
|
|---|
| 28 | *
|
|---|
| 29 | * class CustomError extends Error {
|
|---|
| 30 | * constructor(message: string) {
|
|---|
| 31 | * super(message);
|
|---|
| 32 | * }
|
|---|
| 33 | * }
|
|---|
| 34 | *
|
|---|
| 35 | * // This call will fail and throw an error with the message 'This should throw'
|
|---|
| 36 | * invariant(false, new CustomError('This should throw'));
|
|---|
| 37 | */
|
|---|
| 38 | declare function invariant(condition: unknown, error: Error): asserts condition;
|
|---|
| 39 |
|
|---|
| 40 | export { invariant };
|
|---|