Skip to content

guards.Function.not

github-actions[bot] edited this page Jun 8, 2026 · 2 revisions

@zenstone/ts-utils / guards / not

Function: not()

not(guard): (val) => boolean

Defined in: src/guards/index.ts:516

守卫取反(NOT)

返回运行时取反函数。由于 TS 类型系统不支持否定类型, 返回值为 (val: unknown) => boolean,不作为类型守卫使用。

Parameters

guard

TypeGuard

要取反的守卫函数

Returns

取反后的判断函数

(val) => boolean

Example

const isNotNull = not(isNull);
if (isNotNull(value)) {
  // 运行时正确,但不会收窄类型
}

Clone this wiki locally