Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/typeguardkit/mod.ts>OptionAsserter

A TypeScript module to help construct type assertion functions and type guards.
Latest
class OptionAsserter
implements Asserter<Asserted<DefinedTypeAsserter> | undefined>
Re-export
import { OptionAsserter } from "https://deno.land/x/typeguardkit@0.33.0/mod.ts";

An OptionAsserter is an Asserter for the union of the Type of its definedTypeAsserter with undefined, intended to be used with ObjectAsserter to assert optional properties.

The provided definedTypeAsserter is made accessible as a property of the created OptionAsserter.

The option function can be used to create an OptionAsserter without specifying a typeName.

Example:

import { _string, OptionAsserter } from "typeguardkit";

export const _OptionalString = new OptionAsserter("OptionalString", _string);

Constructors

new
OptionAsserter(typeName: string, definedTypeAsserter: DefinedTypeAsserter)

Type Parameters

DefinedTypeAsserter extends Asserter<unknown>

Properties

readonly
typeName: string

Methods

assert(value: unknown, valueName?: string): Asserted<DefinedTypeAsserter> | undefined