Skip to main content


unless() function

If the result of predicate is true, process will not be executed. unless return the result of process if it is executed, and if the process is not executed, it returns the function argument as is.


declare function unless<T, N extends T, U>(predicate: (input: T) => input is N, process: (input: Exclude<T, N>) => U): (input: T) => N | (U extends void ? undefined : U);


(input: T) => N | (U extends void ? undefined : U)


// it will return only string
const unlessIsString: (input: string | undefined) => string = unless(isString, (input) => {
throw Error("input is undefiend.")