Skip to content

Latest commit

 

History

History
59 lines (47 loc) · 10.3 KB

types.basetypeimpl.md

File metadata and controls

59 lines (47 loc) · 10.3 KB

Home > @skunkteam/types > BaseTypeImpl

BaseTypeImpl class

The base-class of all type-implementations.

Signature:

declare abstract class BaseTypeImpl<ResultType, TypeConfig = unknown> implements TypeLink<ResultType>

Implements: TypeLink<ResultType>

Remarks

All type-implementations must extend this base class. Use createType() to create a Type from a type-implementation.

Properties

Property Modifiers Type Description
autoCast readonly this The same type, but with an auto-casting default parser installed.
autoCastAll readonly this Create a recursive autocasting version of the current type.
basicType

abstract

readonly

BasicType | 'mixed' The kind of values this type validates.
check readonly (this: void, input: unknown) => ResultType Asserts that a value conforms to this Type and returns the input as is, if it does.
enumerableLiteralDomain? readonly Iterable<LiteralValue> (Optional) The set of valid literals if enumerable.
is readonly TypeguardFor<ResultType> A type guard for this Type.
name

abstract

readonly

string The name of the Type.
typeConfig

abstract

readonly

TypeConfig Extra information that is made available by this Type for runtime analysis.

Methods

Method Modifiers Description
accept(visitor) abstract Accept a visitor (visitor pattern).
andThen(fn) Create a function with validated input.
assert(input) Verifies that a value conforms to this Type.
autoCaster(this, value)? protected (Optional) The logic that is used in the autocasting version of the current type.
combineConfig(oldConfig, newConfig) protected Combine two config values into a new value.
construct(input) Calls any registered parsers or auto-caster, verifies that the resulting value conforms to this Type and returns it if it does.
createAutoCastAllType() protected
createResult(input, result, validatorResult) protected Create a Result based on the given ValidationResult.
extendWith(factory) Extend the Type with additional static methods and properties.
literal(input) Calls any registered parsers or auto-caster, verifies that the resulting value conforms to this Type and returns it if it does.
maybeStringify(value) Create a JSON string of the given value, using the type information of the current type. Matches the specs of JSON.stringify.
or(_other) Union this Type with another Type.
stringify(value) Create a JSON string of the given value, using the type information of the current type. Throws if the value is not serializable.
typeParser(input, options)? protected (Optional) Optional pre-processing parser.
typeValidator(input, options)

protected

abstract

The actual validation-logic.
validate(input, options) Validates that a value conforms to this type, and returns a result indicating success or failure (does not throw).
withBrand(name) Create a new instance of this Type with the given name.
withConfig(name, newConfig) Create a new instance of this Type with the additional type-specific config, such as min/max values.
withConstraint(name, constraint) Create a new type use the given constraint function to restrict the current type.
withName(name) Create a new instance of this Type with the given name.
withParser(args) Define a new type with the same specs, but with the given parser and an optional new name.
withValidation(validation) Clone the type with the added validation.