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

Validator


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

Validator


bigint

Public Readonly Variable

Validates that a value is a bigint.

Signature
bigint: Validator<bigint>
References

Validator


boolean

Public Readonly Variable

Validates that a value is boolean.

Signature
boolean: Validator<boolean>
References

Validator


boxModel

Public Readonly Variable

Signature
boxModel: ObjectValidator<{
  x: number
  y: number
  w: number
  h: number
}>
References

ObjectValidator


integer

Public Readonly Variable

Fails if number is not an integer

Signature
integer: Validator<number>
References

Validator


nonZeroInteger

Public Readonly Variable

Fails if value <= 0 and is not an integer

Signature
nonZeroInteger: Validator<number>
References

Validator


nonZeroNumber

Public Readonly Variable

Fails if value <= 0

Signature
nonZeroNumber: Validator<number>
References

Validator


number

Public Readonly Variable

Validates that a value is a finite non-NaN number.

Signature
number: Validator<number>
References

Validator


point

Public Readonly Variable

Signature
point: ObjectValidator<{
  x: number
  y: number
  z: number | undefined
}>
References

ObjectValidator


positiveInteger

Public Readonly Variable

Fails if value < 0 and is not an integer

Signature
positiveInteger: Validator<number>
References

Validator


positiveNumber

Public Readonly Variable

Fails if value < 0

Signature
positiveNumber: Validator<number>
References

Validator


string

Public Readonly Variable

Validates that a value is a string.

Signature
string: Validator<string>
References

Validator


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

Validator


unknownObject

Public Readonly Variable

Signature
unknownObject: Validator<Record<string, unknown>>
References

Validator, Record


Methods

arrayOf

Public Function

Validates that a value is an array whose contents matches the passed-in validator.

Parameters
NameDescription

itemValidator

Validator<T>
Returns
ArrayOfValidator<T>
References

Validator, ArrayOfValidator


dict

Public Function

Validation that an option is a dict with particular keys and values.

Parameters
NameDescription

keyValidator

Validator<Key>

valueValidator

Validator<Value>
Returns
DictValidator<Key, Value>
References

Validator, DictValidator


literal

Public Function

Validates that a value matches another that was passed in.

Example
const trueValidator = T.literal(true)
Parameters
NameDescription

expectedValue

T
Returns
Validator<T>
References

Validator


model

Public Function

A named object with an ID. Errors will be reported as being part of the object with the given name.

Parameters
NameDescription

name

string

validator

Validator<T>
Returns
Validator<T>
References

Validator


object

Public Function

Validate an object has a particular shape.

Parameters
NameDescription

config

{
  readonly [K in keyof Shape]: Validator<Shape[K]>
}
Returns
ObjectValidator<Shape>
References

Validator, ObjectValidator


setEnum

Public Function

Parameters
NameDescription

values

ReadonlySet<T>
Returns
Validator<T>
References

ReadonlySet, Validator


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
NameDescription

key

Key

config

Config
Returns
UnionValidator<Key, Config>
References

UnionValidatorConfig, UnionValidator


Edit this page
Last edited on 11 May 2023