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

x/typeguardkit/core/mod.ts

A TypeScript module to help construct type assertion functions and type guards.
Latest
import * as typeguardkit from "https://deno.land/x/typeguardkit@0.33.0/core/mod.ts";

Classes

An ArrayAsserter is an Asserter for the Array type defined by its elementAsserter, with any additional constraints defined by its ArrayAsserterOptions properties.

An EnumAsserter is an Asserter for the union of the member types of the provided enumObject.

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

A NumberAsserter is an Asserter<number>, with any additional constraints defined by its NumberAsserterOptions properties.

An ObjectAsserter is an Asserter for the object type defined by its propertyAsserters.

An ObjectIntersectionAsserter is an ObjectAsserter for the intersection of the asserted types of the provided ObjectAsserters.

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.

A PartialAsserter is an ObjectAsserter for the asserted type of the provided ObjectAsserter with all properties set to optional.

A PickAsserter is an ObjectAsserter for the type constructed by picking the set of properties Keys from the asserted type of the provided ObjectAsserter.

A RecordAsserter is an Asserter for the Record type defined by its keyAsserter and valueAsserter.

A StringAsserter is an Asserter<string>, with any additional constraints defined by its StringAsserterOptions properties.

A TypeAsserter<Type> is an Asserter<Type> that uses typeGuard to assert whether value is of Type.

A TypeAssertionError should be thrown from an Asserter<Type> when value is not of Type.

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

Variables

missingProperty can be passed to the TypeAssertionError constructor as value to denote a missing object property, as distinct from one set to undefined.

Functions

array can be used to create an ArrayAsserter without specifying a typeName or ArrayAsserterOptions.

assertIs wraps asserter with an assertion signature so value can be narrowed to Type. If asserter.assert throws an error, it will bubble up. Otherwise, assertIs will not return a value, but after calling it, value will be narrowed to Type.

is wraps asserter with a predicate signature, creating a type guard, so that value can be narrowed to Type. If asserter.assert throws an error, is will catch it and return false. Otherwise, is will return true.

objectIntersection can be used to create an ObjectIntersectionAsserter without specifying a typeName.

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

partial can be used to create a PartialAsserter without specifying a typeName.

pick can be used to create a PickAsserter without specifying a typeName.

record can be used to create a RecordAsserter without specifying a typeName.

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

Interfaces

ArrayAsserterOptions are passed to the ArrayAsserter constructor.

ArrayAsserterRules can be assigned to the ArrayAsserterOptions rules property.

An Asserter<Type> has a type assertion method, assert, which should assert whether the provided value is of Type.

A NumberAsserterBound can be assigned to the min and max NumberAsserterOptions.

NumberAsserterOptions are passed to the NumberAsserter constructor.

NumberAsserterRules can be assigned to the NumberAsserterOptions rules property.

StringAsserterOptions are passed to the StringAsserter constructor.

A StringAsserterRegex can be assigned to the StringAsserterOptions regex property.

StringAsserterRules can be assigned to the StringAsserterOptions rules property.

TypeAssertionErrorOptions can be passed to the TypeAssertionError constructor.

A Validator<Type> has a validate method, which should check value meets any runtime-only constraints of Type, and return any issues. This should not include constraints of any Validators for properties or elements of Type.

Type Aliases

Asserted constructs a type consisting of the asserted type of AsserterImplementation.