Skip to content

guards.Function.or

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

@zenstone/ts-utils / guards / or

Function: or()

or<G>(...guards): TypeGuard<InferGuard<G[number]>>

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

组合守卫(OR)

任意一个守卫通过即返回 true,自动推断联合类型

Type Parameters

G

G extends [TypeGuard<any>, ...TypeGuard<any>[]]

Parameters

guards

...G

一个或多个守卫函数

Returns

TypeGuard<InferGuard<G[number]>>

组合后的守卫函数

Example

const isStrOrNum = or(isStr, isNumber);
if (isStrOrNum(value)) {
  // value: string | number
}

Clone this wiki locally