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.