feat: add useful error assertion message
This commit is contained in:
+7
-3
@@ -124,11 +124,15 @@ export async function waitForDeploymentRollout(
|
||||
|
||||
export function throwWhen<T, Narrowed extends T>(
|
||||
condition: (arg: T) => arg is Narrowed,
|
||||
message?: string,
|
||||
): (arg: T) => Exclude<T, Narrowed>;
|
||||
export function throwWhen<T>(condition: (arg: T) => unknown): (arg: T) => T;
|
||||
export function throwWhen<T>(condition: (arg: T) => unknown) {
|
||||
export function throwWhen<T>(
|
||||
condition: (arg: T) => unknown,
|
||||
message?: string,
|
||||
): (arg: T) => T;
|
||||
export function throwWhen<T>(condition: (arg: T) => unknown, message?: string) {
|
||||
return (arg: T) => {
|
||||
if (condition(arg)) throw new Error("Condition matched");
|
||||
if (condition(arg)) throw new Error(message ?? "Condition matched");
|
||||
return arg;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user