Array of types in the union
The type guards for each type in the union
A type guard for the union of all the given type guards
type A = { a: number };
type B = { b: string };
type C = A | B;
const isA = isType<A>({ a: isNumber });
const isB = isType<B>({ b: isString });
const isC = isUnion(isA, isB) satisfies TypeGuard<C>; // or isA.or(isB)
isC({ a: 1 }); // true
isC({ b: "hello" }); // true
isC({ a: 1, b: "hello" }); // true
isC({}); // false
Creates a
UnionTypeGuardthat checks that the value matches any of the provided type guards.Best practice: use
satisfieson the result ofisUnionto ensure the result is of the expected union type.Can be shortened with
TypeGuard.or.