Skip to content

Latest commit

 

History

History
121 lines (108 loc) · 22.5 KB

File metadata and controls

121 lines (108 loc) · 22.5 KB

Home > @skunkteam/types

types package

Runtime type-validation with derived TypeScript types.

Classes

Class Description
ArrayType The implementation behind types created with array().
BaseObjectLikeTypeImpl The base implementation for all object-like Types.
BaseTypeImpl The base-class of all type-implementations.
InterfaceType The implementation behind types created with object() and partial().
IntersectionType The implementation behind types created with intersection() and BaseObjectLikeTypeImpl.and().
KeyofType The implementation behind types created with keyof() and valueof().
LiteralType The implementation behind types created with literal() and nullType, undefinedType and voidType.
RecordType The implementation behind types created with record().
SimpleType Implementation for simple types such as primitive types.
UnionType The implementation behind types created with union() and BaseTypeImpl.or().
ValidationError The error that is thrown on any validation- or parse-error within this library.

Functions

Function Description
array(args) Create a type that checks whether the input is an array and all elements conform to the given elementType.
booleanAutoCaster(input)
createType(impl, override) Create a Type from the given type-implementation.
intersection(args) Intersect the given types.
isType(value) Type-guard that asserts that a given value is a Type.
keyof(args)
literal(value)
numberAutoCaster(input)
object(args) Create a type-validator that validates (or parses) an object structure.
partial(args) Create a type-validator that validates (or parses) an object structure with only optional properties.
pattern(name, regExp, customMessage)
printKey(key) Print a property-key in a JavaScript compatible way.
printPath(path) Print a property-path in a "JavaScripty way".
printValue(input, budget, visited) Print an unknown value with a given character budget (default: 50).
record(args) Note: record has strict validation by default, while type does not have strict validation, both are strict in construction though. TODO: document
reportError(root, level, omitInput) Creates an human-readable error report of the given failure.
union(args)
valueof(args)

Interfaces

Interface Description
ArrayTypeConfig Configuration of additional checks on array types.
Failure A failed validation result.
InterfaceTypeOptions Options for object().
LengthChecksConfig
ParserOptions Options that can be passed to BaseTypeImpl.withParser().
SimpleTypeOptions
StringTypeConfig Configuration of additional checks on string types.
Success A successful validation result.
TypedPropertyInformation Interface that provides more detailed type-information about the props and propsInfo properties of the validator.
TypeLink An object that has an associated TypeScript type.
ValidationOptions
Visitor Interface for a visitor that is accepted by all types (classic visitor-pattern).

Variables

Variable Description
boolean Built-in validator for boolean-values.
int
nullType
number
string Built-in validator for string-values.
undefinedType
unknown Built-in validator that accepts all values.
unknownArray Built-in validator that accepts all arrays.
unknownRecord Built-in validator that accepts all objects (null is not accepted).
voidType

Type Aliases

Type Alias Description
ArrayViolation The supported additional checks on array types.
BasicType Basic categories of types.
Branded Create a Branded type with a given BrandName.
CustomMessage The type for optional custom messages
DeepUnbranded Unbrand a given type (recursive).
FailureDetails Individual message with info about the performed validation for error-reporting.
FullType
int
IntersectionOfTypeTuple
LengthViolation
LiteralValue The supported types of literals.
MergeIntersection Merge an intersection of types into one type, mostly for tooltip-readability in IDEs.
MessageDetails Individual message details with optional info about the performed validation.
NumberTypeConfig Configuration of additional checks on numeric types.
NumberViolation The supported additional checks on numeric types.
ObjectType A type-validator/-parser that validates or parses object-like type ResultType.
OneOrMore An Array with at least one element.
PartialType
Properties The properties of an object type.
PropertiesInfo Properties of an object type, including per-property optionality.
PropertiesOfTypeTuple
Result The result of a type validation.
StringViolation The supported additional checks on string types.
The Obtains the TypeScript type of the given runtime Type-checker. Aka TypeOf.
Transposed
Type A type-validator/-parser that validates or parses ResultType.
TypeImpl The Type with the given type implementation.
TypeOf Obtains the TypeScript type of the given runtime Type-checker. Aka The.
TypeOfProperties Translates the type of a Properties-object into the proper TypeScript type to be used in user-code.
Unbranded Unbrand a given type (not recursive).
unknownArray Built-in validator that accepts all arrays.
unknownRecord Built-in validator that accepts all objects (null is not accepted).
ValidationDetails Information about the performed validation for error-reporting.
ValidationMode The validation mode to use.
ValidationResult The possible return values inside validation and constraint functions.
Validator The validation-logic as needed by BaseTypeImpl.withConstraint() and BaseTypeImpl.withValidation().
WithBrands
Writable The opposite of the built-in Readonly<...> type.