Skip to main content
Module

x/typeguardkit/mod.ts>UnionAsserter

A TypeScript module to help construct type assertion functions and type guards.
Latest
class UnionAsserter
implements Asserter<Asserted<Asserters[number]>>
Re-export
import { UnionAsserter } from "https://deno.land/x/typeguardkit@0.32.1/mod.ts";

A UnionAsserter is an Asserter for the union of the Types of its memberAsserters.

The provided memberAsserters are made accessible as a property of the created UnionAsserter.

The union function can be used to create a UnionAsserter without specifying a typeName.

Example:

import { _null, _string, Asserted, UnionAsserter } from "typeguardkit";

export const _stringOrNull = new UnionAsserter(
  "stringOrNull",
  [_string, _null],
);

export type stringOrNull = Asserted<typeof _stringOrNull>;

Constructors

new
UnionAsserter(typeName: string, memberAsserters: Asserters)

Type Parameters

Asserters extends ReadonlyArray<Asserter<unknown>>

Properties

readonly
typeName: string

Methods

assert(value: unknown, valueName?: string): Asserted<Asserters[number]>