feat: add useful error assertion message

This commit is contained in:
2026-08-20 15:47:05 +07:00 Unverified
parent 67462e744b
commit 23b4ccaa80
2 changed files with 13 additions and 4 deletions
+7 -3
View File
@@ -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;
};
}