UNPKG

2.64 kBTypeScriptView Raw
1/**
2 * @since 2.2.0
3 */
4import { Literal, Schemable1, WithRefinement1, WithUnion1, WithUnknownContainers1 } from './Schemable';
5/**
6 * @since 2.2.0
7 */
8export interface Guard<A> {
9 is: (u: unknown) => u is A;
10}
11/**
12 * @since 2.2.2
13 */
14export declare type TypeOf<G> = G extends Guard<infer A> ? A : never;
15/**
16 * @since 2.2.0
17 */
18export declare function literal<A extends ReadonlyArray<Literal>>(...values: A): Guard<A[number]>;
19/**
20 * @since 2.2.0
21 */
22export declare const never: Guard<never>;
23/**
24 * @since 2.2.0
25 */
26export declare const string: Guard<string>;
27/**
28 * @since 2.2.0
29 */
30export declare const number: Guard<number>;
31/**
32 * @since 2.2.0
33 */
34export declare const boolean: Guard<boolean>;
35/**
36 * @since 2.2.0
37 */
38export declare const UnknownArray: Guard<Array<unknown>>;
39/**
40 * @since 2.2.0
41 */
42export declare const UnknownRecord: Guard<Record<string, unknown>>;
43/**
44 * @since 2.2.0
45 */
46export declare function refinement<A, B extends A>(from: Guard<A>, refinement: (a: A) => a is B): Guard<B>;
47/**
48 * @since 2.2.0
49 */
50export declare function nullable<A>(or: Guard<A>): Guard<null | A>;
51/**
52 * @since 2.2.0
53 */
54export declare function type<A>(properties: {
55 [K in keyof A]: Guard<A[K]>;
56}): Guard<{
57 [K in keyof A]: A[K];
58}>;
59/**
60 * @since 2.2.0
61 */
62export declare function partial<A>(properties: {
63 [K in keyof A]: Guard<A[K]>;
64}): Guard<Partial<{
65 [K in keyof A]: A[K];
66}>>;
67/**
68 * @since 2.2.0
69 */
70export declare function record<A>(codomain: Guard<A>): Guard<Record<string, A>>;
71/**
72 * @since 2.2.0
73 */
74export declare function array<A>(items: Guard<A>): Guard<Array<A>>;
75/**
76 * @since 2.2.0
77 */
78export declare function tuple<A extends ReadonlyArray<unknown>>(...components: {
79 [K in keyof A]: Guard<A[K]>;
80}): Guard<A>;
81/**
82 * @since 2.2.0
83 */
84export declare function intersection<A, B>(left: Guard<A>, right: Guard<B>): Guard<A & B>;
85/**
86 * @since 2.2.0
87 */
88export declare function union<A extends ReadonlyArray<unknown>>(...members: {
89 [K in keyof A]: Guard<A[K]>;
90}): Guard<A[number]>;
91/**
92 * @since 2.2.0
93 */
94export declare function sum<T extends string>(tag: T): <A>(members: {
95 [K in keyof A]: Guard<A[K]>;
96}) => Guard<A[keyof A]>;
97/**
98 * @since 2.2.0
99 */
100export declare function lazy<A>(f: () => Guard<A>): Guard<A>;
101/**
102 * @since 2.2.0
103 */
104export declare const URI = "io-ts/Guard";
105/**
106 * @since 2.2.0
107 */
108export declare type URI = typeof URI;
109declare module 'fp-ts/es6/HKT' {
110 interface URItoKind<A> {
111 readonly [URI]: Guard<A>;
112 }
113}
114/**
115 * @since 2.2.3
116 */
117export declare const schemableGuard: Schemable1<URI> & WithUnknownContainers1<URI> & WithUnion1<URI> & WithRefinement1<URI>;