T
None Namespace
Table of Contents
Signature
Properties
any
Public Readonly Variable
Validation that accepts any value. Generally this should be avoided, but you can use it as an escape hatch if you want to work without validations for e.g. a prototype.
Signature
any: Validator<any>
References
array
Public Readonly Variable
Validates that a value is an array. To check the contents of the array, use T.arrayOf.
Signature
array: Validator<unknown[]>
References
bigint
Public Readonly Variable
Validates that a value is a bigint.
Signature
bigint: Validator<bigint>
References
boolean
Public Readonly Variable
Validates that a value is boolean.
Signature
boolean: Validator<boolean>
References
boxModel
Public Readonly Variable
Signature
boxModel: ObjectValidator<{
x: number
y: number
w: number
h: number
}>
References
integer
Public Readonly Variable
Fails if number is not an integer
Signature
integer: Validator<number>
References
nonZeroInteger
Public Readonly Variable
Fails if value <= 0 and is not an integer
Signature
nonZeroInteger: Validator<number>
References
nonZeroNumber
Public Readonly Variable
Fails if value <= 0
Signature
nonZeroNumber: Validator<number>
References
number
Public Readonly Variable
Validates that a value is a finite non-NaN number.
Signature
number: Validator<number>
References
point
Public Readonly Variable
Signature
point: ObjectValidator<{
x: number
y: number
z: number | undefined
}>
References
positiveInteger
Public Readonly Variable
Fails if value < 0 and is not an integer
Signature
positiveInteger: Validator<number>
References
positiveNumber
Public Readonly Variable
Fails if value < 0
Signature
positiveNumber: Validator<number>
References
string
Public Readonly Variable
Validates that a value is a string.
Signature
string: Validator<string>
References
unknown
Public Readonly Variable
Validation that accepts any value. Useful as a starting point for building your own custom validations.
Signature
unknown: Validator<unknown>
References
unknownObject
Public Readonly Variable
Signature
unknownObject: Validator<Record<string, unknown>>
References
Methods
arrayOf
Public Function
Validates that a value is an array whose contents matches the passed-in validator.
Parameters
Name | Description |
---|---|
|
|
Returns
ArrayOfValidator<T>
References
dict
Public Function
Validation that an option is a dict with particular keys and values.
Parameters
Name | Description |
---|---|
|
|
|
|
Returns
DictValidator<Key, Value>
References
literal
Public Function
Validates that a value matches another that was passed in.
Example
const trueValidator = T.literal(true)
Parameters
Name | Description |
---|---|
|
|
Returns
Validator<T>
References
model
Public Function
A named object with an ID. Errors will be reported as being part of the object with the given name.
Parameters
Name | Description |
---|---|
|
|
|
|
Returns
Validator<T>
References
object
Public Function
Validate an object has a particular shape.
Parameters
Name | Description |
---|---|
|
|
Returns
ObjectValidator<Shape>
References
setEnum
Public Function
Parameters
Name | Description |
---|---|
|
|
Returns
Validator<T>
References
union
Public Function
Validate a union of several object types. Each object must have a property matching key
which should be a unique string.
Example
const catValidator = T.object({ kind: T.value('cat'), meow: T.boolean })
const dogValidator = T.object({ kind: T.value('dog'), bark: T.boolean })
const animalValidator = T.union('kind', {
cat: catValidator,
dog: dogValidator,
})
Parameters
Name | Description |
---|---|
|
|
|
|
Returns
UnionValidator<Key, Config>
References
UnionValidatorConfig, UnionValidator