Skip to main content
Module

x/typeguardkit/mod.ts>LiteralUnionAsserter

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

A LiteralUnionAsserter is an Asserter for the union of its values.

The provided values are made accessible as a property of the created LiteralUnionAsserter.

The values array should be asserted as const if defined outside the constructor call.

Example:

import { Asserted, LiteralUnionAsserter } from "typeguardkit";

export const _Direction = new LiteralUnionAsserter(
  "Direction",
  ["up", "right", "down", "left"],
);

export type Direction = Asserted<typeof _Direction>;

Constructors

new
LiteralUnionAsserter(typeName: string, values: Values)

Type Parameters

Values extends ReadonlyArray<string | number | boolean>

Properties

readonly
typeName: string

Methods

assert(value: unknown, valueName?: string): Values[number]