Guard overview
This module is experimental
Experimental features are published in order to get early feedback from the community, see these tracking issues for further discussions and enhancements.
A feature tagged as Experimental is in a high state of flux, you’re at risk of it changing without notice.
Added in v2.2.0
Table of contents
combinators
alt
Signature
export declare const alt: <I, A extends I>(that: () => Guard<I, A>) => (me: Guard<I, A>) => Guard<I, A>
Added in v2.2.8
array
Signature
export declare const array: <A>(item: Guard<unknown, A>) => Guard<unknown, A[]>
Added in v2.2.0
compose
Signature
export declare const compose: <I, A extends I, B extends A>(to: Guard<A, B>) => (from: Guard<I, A>) => Guard<I, B>
Added in v2.2.8
id
Signature
export declare const id: <A>() => Guard<A, A>
Added in v2.2.8
intersect
Signature
export declare const intersect: <B>(right: Guard<unknown, B>) => <A>(left: Guard<unknown, A>) => Guard<unknown, A & B>
Added in v2.2.0
lazy
Signature
export declare const lazy: <A>(f: () => Guard<unknown, A>) => Guard<unknown, A>
Added in v2.2.0
nullable
Signature
export declare const nullable: <I, A extends I>(or: Guard<I, A>) => Guard<I | null, A | null>
Added in v2.2.0
partial
Signature
export declare const partial: <A>(properties: { [K in keyof A]: Guard<unknown, A[K]> }) => Guard<
unknown,
Partial<{ [K in keyof A]: A[K] }>
>
Added in v2.2.0
readonly
Signature
export declare const readonly: <I, A extends I>(guard: Guard<I, A>) => Guard<I, Readonly<A>>
Added in v2.2.15
record
Signature
export declare const record: <A>(codomain: Guard<unknown, A>) => Guard<unknown, Record<string, A>>
Added in v2.2.0
refine
Signature
export declare const refine: <I, A extends I, B extends A>(
refinement: Refinement<A, B>
) => (from: Guard<I, A>) => Guard<I, B>
Added in v2.2.0
struct
Signature
export declare const struct: <A>(properties: { [K in keyof A]: Guard<unknown, A[K]> }) => Guard<
unknown,
{ [K in keyof A]: A[K] }
>
Added in v2.2.15
sum
Signature
export declare const sum: <T extends string>(
tag: T
) => <A>(members: { [K in keyof A]: Guard<unknown, A[K] & Record<T, K>> }) => Guard<unknown, A[keyof A]>
Added in v2.2.0
tuple
Signature
export declare const tuple: <A extends readonly unknown[]>(
...components: { [K in keyof A]: Guard<unknown, A[K]> }
) => Guard<unknown, A>
Added in v2.2.0
union
Signature
export declare const union: <A extends readonly [unknown, ...unknown[]]>(
...members: { [K in keyof A]: Guard<unknown, A[K]> }
) => Guard<unknown, A[number]>
Added in v2.2.0
zero
Signature
export declare const zero: <I, A extends I>() => Guard<I, A>
Added in v2.2.8
type
Use struct
instead.
Signature
export declare const type: <A>(properties: { [K in keyof A]: Guard<unknown, A[K]> }) => Guard<
unknown,
{ [K in keyof A]: A[K] }
>
Added in v2.2.0
constructors
literal
Signature
export declare const literal: <A extends readonly [L, ...L[]], L extends S.Literal = S.Literal>(
...values: A
) => Guard<unknown, A[number]>
Added in v2.2.0
instances
Schemable
Signature
export declare const Schemable: S.Schemable1<'io-ts/Guard'>
Added in v2.2.8
URI
Signature
export declare const URI: 'io-ts/Guard'
Added in v2.2.0
URI (type alias)
Signature
export type URI = typeof URI
Added in v2.2.0
WithRefine
Signature
export declare const WithRefine: S.WithRefine1<'io-ts/Guard'>
Added in v2.2.8
WithUnion
Signature
export declare const WithUnion: S.WithUnion1<'io-ts/Guard'>
Added in v2.2.8
WithUnknownContainers
Signature
export declare const WithUnknownContainers: S.WithUnknownContainers1<'io-ts/Guard'>
Added in v2.2.8
model
Guard (interface)
Signature
export interface Guard<I, A extends I> {
is: (i: I) => i is A
}
Added in v2.2.8
primitives
UnknownArray
Signature
export declare const UnknownArray: Guard<unknown, unknown[]>
Added in v2.2.0
UnknownRecord
Signature
export declare const UnknownRecord: Guard<unknown, Record<string, unknown>>
Added in v2.2.0
boolean
Signature
export declare const boolean: Guard<unknown, boolean>
Added in v2.2.0
number
Note: NaN
is excluded.
Signature
export declare const number: Guard<unknown, number>
Added in v2.2.0
string
Signature
export declare const string: Guard<unknown, string>
Added in v2.2.0
utils
InputOf (type alias)
Signature
export type InputOf<G> = G extends Guard<infer I, any> ? I : never
Added in v2.2.8
TypeOf (type alias)
Signature
export type TypeOf<G> = G extends Guard<any, infer A> ? A : never
Added in v2.2.2