throwIf() function
述語関数が true を返す場合、errの戻り値をスローします。
デフォルトのスロー関数はidentityです。
Signature:
typescript
declare function throwIf<T, N extends T>(
predicate: (input: T) => input is N,
err?: (input: N) => unknown,
): (input: T) => Exclude<T, N>;Example
ts
pipe(
fn(), // return type is string | undefined
throwIf(isUndefined, (err) => Error("return of fn() is undefined")),
// err is undefined, and it is return of fn
(input) => input, // input is string
);