Home > @skunkteam/types > BaseTypeImpl
The base-class of all type-implementations.
Signature:
declare abstract class BaseTypeImpl<ResultType, TypeConfig = unknown> implements TypeLink<ResultType>
Implements: TypeLink<ResultType>
All type-implementations must extend this base class. Use createType() to create a Type from a type-implementation.
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 |
|
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. |
customValidators |
|
ReadonlyArray<Validator<unknown>> | Additional custom validation added using withValidation or withConstraint. |
enumerableLiteralDomain? | readonly |
Iterable<LiteralValue> | (Optional) The set of valid literals if enumerable. |
is | readonly |
TypeguardFor<ResultType> | A type guard for this Type. |
name |
|
string | The name of the Type. |
typeConfig |
|
TypeConfig | Extra information that is made available by this Type for runtime analysis. |
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) |
|
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 based on the current type and use the given constraint function as validation. | |
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. |