Skip to content

negate() function

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

Signature:

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

Example

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

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

Open Source Code

Released under the Apache-2.0 License.