Skip to main content

negate

negate() function

Create a function that returns the opposite result of a predicate function

Signature:
declare function negate<T>(predicate: (input: T) => boolean): (input: T) => boolean;

declare function negate<T, N extends T>(predicate: (input: T) => input is N): (input: T) => input is Exclude<T, N>;

Example

const isDefined: (input: string | undefined) => input is string = negate(isUndefined)<string | undefined>

const isDefined: (input: unknown) => boolean = negate((input) => input === undefined)

Open Source Code