Skip to content

negate() 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.