UNPKG

30.7 kBTypeScriptView Raw
1/**
2 * @since 1.0.0
3 */
4import { Either } from 'fp-ts/lib/Either'
5import { Predicate, Refinement } from 'fp-ts/lib/function'
6/**
7 * @category Decode error
8 * @since 1.0.0
9 */
10export interface ContextEntry {
11 readonly key: string
12 readonly type: Decoder<any, any>
13 /** the input data */
14 readonly actual?: unknown
15}
16/**
17 * @category Decode error
18 * @since 1.0.0
19 */
20export interface Context extends ReadonlyArray<ContextEntry> {}
21/**
22 * @category Decode error
23 * @since 1.0.0
24 */
25export interface ValidationError {
26 /** the offending (sub)value */
27 readonly value: unknown
28 /** where the error originated */
29 readonly context: Context
30 /** optional custom error message */
31 readonly message?: string
32}
33/**
34 * @category Decode error
35 * @since 1.0.0
36 */
37export interface Errors extends Array<ValidationError> {}
38/**
39 * @category Decode error
40 * @since 1.0.0
41 */
42export declare type Validation<A> = Either<Errors, A>
43/**
44 * @category Decode error
45 * @since 1.0.0
46 */
47export declare const failures: <T>(errors: Errors) => Validation<T>
48/**
49 * @category Decode error
50 * @since 1.0.0
51 */
52export declare const failure: <T>(value: unknown, context: Context, message?: string | undefined) => Either<Errors, T>
53/**
54 * @category Decode error
55 * @since 1.0.0
56 */
57export declare const success: <T>(value: T) => Validation<T>
58/**
59 * @since 1.0.0
60 */
61export declare type Is<A> = (u: unknown) => u is A
62/**
63 * @since 1.0.0
64 */
65export declare type Validate<I, A> = (i: I, context: Context) => Validation<A>
66/**
67 * @since 1.0.0
68 */
69export declare type Decode<I, A> = (i: I) => Validation<A>
70/**
71 * @since 1.0.0
72 */
73export declare type Encode<A, O> = (a: A) => O
74/**
75 * @since 1.0.0
76 */
77export interface Any extends Type<any, any, any> {}
78/**
79 * @since 1.0.0
80 */
81export interface Mixed extends Type<any, any, unknown> {}
82/**
83 * @category Codec
84 * @since 1.0.0
85 */
86export declare type TypeOf<C extends Any> = C['_A']
87/**
88 * @category Codec
89 * @since 1.0.0
90 */
91export declare type InputOf<C extends Any> = C['_I']
92/**
93 * @category Codec
94 * @since 1.0.0
95 */
96export declare type OutputOf<C extends Any> = C['_O']
97/**
98 * @category Codec
99 * @since 1.0.0
100 */
101export interface Decoder<I, A> {
102 readonly name: string
103 readonly validate: Validate<I, A>
104 readonly decode: Decode<I, A>
105}
106/**
107 * @category Codec
108 * @since 1.0.0
109 */
110export interface Encoder<A, O> {
111 readonly encode: Encode<A, O>
112}
113/**
114 * @category Codec
115 * @since 1.0.0
116 */
117export declare class Type<A, O = A, I = unknown> implements Decoder<I, A>, Encoder<A, O> {
118 /** a unique name for this codec */
119 readonly name: string
120 /** a custom type guard */
121 readonly is: Is<A>
122 /** succeeds if a value of type I can be decoded to a value of type A */
123 readonly validate: Validate<I, A>
124 /** converts a value of type A to a value of type O */
125 readonly encode: Encode<A, O>
126 /**
127 * @since 1.0.0
128 */
129 readonly _A: A
130 /**
131 * @since 1.0.0
132 */
133 readonly _O: O
134 /**
135 * @since 1.0.0
136 */
137 readonly _I: I
138 constructor(
139 /** a unique name for this codec */
140 name: string,
141 /** a custom type guard */
142 is: Is<A>,
143 /** succeeds if a value of type I can be decoded to a value of type A */
144 validate: Validate<I, A>,
145 /** converts a value of type A to a value of type O */
146 encode: Encode<A, O>
147 )
148 /**
149 * @since 1.0.0
150 */
151 pipe<B, IB, A extends IB, OB extends A>(this: Type<A, O, I>, ab: Type<B, OB, IB>, name?: string): Type<B, O, I>
152 /**
153 * @since 1.0.0
154 */
155 asDecoder(): Decoder<I, A>
156 /**
157 * @since 1.0.0
158 */
159 asEncoder(): Encoder<A, O>
160 /**
161 * a version of `validate` with a default context
162 * @since 1.0.0
163 */
164 decode(i: I): Validation<A>
165}
166/**
167 * @since 1.0.0
168 */
169export declare const identity: <A>(a: A) => A
170/**
171 * @since 1.0.0
172 */
173export declare function getFunctionName(f: Function): string
174/**
175 * @since 1.0.0
176 */
177export declare function getContextEntry(key: string, decoder: Decoder<any, any>): ContextEntry
178/**
179 * @since 1.0.0
180 */
181export declare function appendContext(c: Context, key: string, decoder: Decoder<any, any>, actual?: unknown): Context
182/**
183 * @since 1.0.0
184 */
185export interface AnyProps {
186 [key: string]: Any
187}
188/**
189 * @since 1.0.0
190 */
191export declare type TypeOfProps<P extends AnyProps> = {
192 [K in keyof P]: TypeOf<P[K]>
193}
194/**
195 * @since 1.0.0
196 */
197export declare type OutputOfProps<P extends AnyProps> = {
198 [K in keyof P]: OutputOf<P[K]>
199}
200/**
201 * @since 1.0.0
202 */
203export interface Props {
204 [key: string]: Mixed
205}
206/**
207 * @since 1.0.0
208 */
209export declare type TypeOfPartialProps<P extends AnyProps> = {
210 [K in keyof P]?: TypeOf<P[K]>
211}
212/**
213 * @since 1.0.0
214 */
215export declare type OutputOfPartialProps<P extends AnyProps> = {
216 [K in keyof P]?: OutputOf<P[K]>
217}
218/**
219 * @since 1.0.0
220 */
221export declare type TypeOfDictionary<D extends Any, C extends Any> = {
222 [K in TypeOf<D>]: TypeOf<C>
223}
224/**
225 * @since 1.0.0
226 */
227export declare type OutputOfDictionary<D extends Any, C extends Any> = {
228 [K in OutputOf<D>]: OutputOf<C>
229}
230/**
231 * @since 1.1.0
232 */
233export interface HasPropsRefinement extends RefinementType<HasProps, any, any, any> {}
234/**
235 * @since 1.1.0
236 */
237export interface HasPropsReadonly extends ReadonlyType<HasProps, any, any, any> {}
238/**
239 * @since 1.1.0
240 */
241export interface HasPropsIntersection extends IntersectionType<Array<HasProps>, any, any, any> {}
242/**
243 * @since 1.1.0
244 */
245export declare type HasProps =
246 | HasPropsRefinement
247 | HasPropsReadonly
248 | HasPropsIntersection
249 | InterfaceType<any, any, any, any>
250 | StrictType<any, any, any, any>
251 | PartialType<any, any, any, any>
252/**
253 * @since 1.0.0
254 */
255export declare class NullType extends Type<null> {
256 /**
257 * @since 1.0.0
258 */
259 readonly _tag: 'NullType'
260 constructor()
261}
262/**
263 * @since 1.5.3
264 */
265export interface NullC extends NullType {}
266/**
267 * @category primitives
268 * @since 1.0.0
269 */
270export declare const nullType: NullC
271/**
272 * @since 1.0.0
273 */
274export declare class UndefinedType extends Type<undefined> {
275 /**
276 * @since 1.0.0
277 */
278 readonly _tag: 'UndefinedType'
279 constructor()
280}
281/**
282 * @since 1.5.3
283 */
284export interface UndefinedC extends UndefinedType {}
285declare const undefinedType: UndefinedC
286/**
287 * @since 1.2.0
288 */
289export declare class VoidType extends Type<void> {
290 /**
291 * @since 1.0.0
292 */
293 readonly _tag: 'VoidType'
294 constructor()
295}
296/**
297 * @since 1.5.3
298 */
299export interface VoidC extends VoidType {}
300/**
301 * @category primitives
302 * @since 1.2.0
303 */
304export declare const voidType: VoidC
305/**
306 * @since 1.5.0
307 */
308export declare class UnknownType extends Type<unknown> {
309 /**
310 * @since 1.0.0
311 */
312 readonly _tag: 'UnknownType'
313 constructor()
314}
315/**
316 * @since 1.5.3
317 */
318export interface UnknownC extends UnknownType {}
319/**
320 * @category primitives
321 * @since 1.5.0
322 */
323export declare const unknown: UnknownC
324/**
325 * @since 1.0.0
326 */
327export declare class StringType extends Type<string> {
328 /**
329 * @since 1.0.0
330 */
331 readonly _tag: 'StringType'
332 constructor()
333}
334/**
335 * @since 1.5.3
336 */
337export interface StringC extends StringType {}
338/**
339 * @category primitives
340 * @since 1.0.0
341 */
342export declare const string: StringC
343/**
344 * @since 1.0.0
345 */
346export declare class NumberType extends Type<number> {
347 /**
348 * @since 1.0.0
349 */
350 readonly _tag: 'NumberType'
351 constructor()
352}
353/**
354 * @since 1.5.3
355 */
356export interface NumberC extends NumberType {}
357/**
358 * @category primitives
359 * @since 1.0.0
360 */
361export declare const number: NumberC
362/**
363 * @since 2.1.0
364 */
365export declare class BigIntType extends Type<bigint> {
366 /**
367 * @since 1.0.0
368 */
369 readonly _tag: 'BigIntType'
370 constructor()
371}
372/**
373 * @since 2.1.0
374 */
375export interface BigIntC extends BigIntType {}
376/**
377 * @category primitives
378 * @since 2.1.0
379 */
380export declare const bigint: BigIntC
381/**
382 * @since 1.0.0
383 */
384export declare class BooleanType extends Type<boolean> {
385 /**
386 * @since 1.0.0
387 */
388 readonly _tag: 'BooleanType'
389 constructor()
390}
391/**
392 * @since 1.5.3
393 */
394export interface BooleanC extends BooleanType {}
395/**
396 * @category primitives
397 * @since 1.0.0
398 */
399export declare const boolean: BooleanC
400/**
401 * @since 1.0.0
402 */
403export declare class AnyArrayType extends Type<Array<unknown>> {
404 /**
405 * @since 1.0.0
406 */
407 readonly _tag: 'AnyArrayType'
408 constructor()
409}
410/**
411 * @since 1.5.3
412 */
413export interface UnknownArrayC extends AnyArrayType {}
414/**
415 * @category primitives
416 * @since 1.7.1
417 */
418export declare const UnknownArray: UnknownArrayC
419/**
420 * @since 1.0.0
421 */
422export declare class AnyDictionaryType extends Type<{
423 [key: string]: unknown
424}> {
425 /**
426 * @since 1.0.0
427 */
428 readonly _tag: 'AnyDictionaryType'
429 constructor()
430}
431/**
432 * @since 1.5.3
433 */
434export interface UnknownRecordC extends AnyDictionaryType {}
435/**
436 * @category primitives
437 * @since 1.7.1
438 */
439export declare const UnknownRecord: UnknownRecordC
440export {
441 /**
442 * @category primitives
443 * @since 1.0.0
444 */
445 nullType as null,
446 /**
447 * @category primitives
448 * @since 1.0.0
449 */
450 undefinedType as undefined,
451 /**
452 * @category primitives
453 * @since 1.0.0
454 */
455 voidType as void
456}
457declare type LiteralValue = string | number | boolean
458/**
459 * @since 1.0.0
460 */
461export declare class LiteralType<V extends LiteralValue> extends Type<V> {
462 readonly value: V
463 /**
464 * @since 1.0.0
465 */
466 readonly _tag: 'LiteralType'
467 constructor(
468 name: string,
469 is: LiteralType<V>['is'],
470 validate: LiteralType<V>['validate'],
471 encode: LiteralType<V>['encode'],
472 value: V
473 )
474}
475/**
476 * @since 1.5.3
477 */
478export interface LiteralC<V extends LiteralValue> extends LiteralType<V> {}
479/**
480 * @category constructors
481 * @since 1.0.0
482 */
483export declare function literal<V extends LiteralValue>(value: V, name?: string): LiteralC<V>
484/**
485 * @since 1.0.0
486 */
487export declare class KeyofType<
488 D extends {
489 [key: string]: unknown
490 }
491> extends Type<keyof D> {
492 readonly keys: D
493 /**
494 * @since 1.0.0
495 */
496 readonly _tag: 'KeyofType'
497 constructor(
498 name: string,
499 is: KeyofType<D>['is'],
500 validate: KeyofType<D>['validate'],
501 encode: KeyofType<D>['encode'],
502 keys: D
503 )
504}
505/**
506 * @since 1.5.3
507 */
508export interface KeyofC<
509 D extends {
510 [key: string]: unknown
511 }
512> extends KeyofType<D> {}
513/**
514 * @category constructors
515 * @since 1.0.0
516 */
517export declare function keyof<
518 D extends {
519 [key: string]: unknown
520 }
521>(keys: D, name?: string): KeyofC<D>
522/**
523 * @since 1.0.0
524 */
525export declare class RefinementType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
526 readonly type: C
527 readonly predicate: Predicate<A>
528 /**
529 * @since 1.0.0
530 */
531 readonly _tag: 'RefinementType'
532 constructor(
533 name: string,
534 is: RefinementType<C, A, O, I>['is'],
535 validate: RefinementType<C, A, O, I>['validate'],
536 encode: RefinementType<C, A, O, I>['encode'],
537 type: C,
538 predicate: Predicate<A>
539 )
540}
541declare const _brand: unique symbol
542/**
543 * @since 1.8.1
544 */
545export interface Brand<B> {
546 readonly [_brand]: B
547}
548/**
549 * @since 1.8.1
550 */
551export declare type Branded<A, B> = A & Brand<B>
552/**
553 * @since 1.8.1
554 */
555export interface BrandC<C extends Any, B> extends RefinementType<C, Branded<TypeOf<C>, B>, OutputOf<C>, InputOf<C>> {}
556/**
557 * @category combinators
558 * @since 1.8.1
559 */
560export declare function brand<
561 C extends Any,
562 N extends string,
563 B extends {
564 readonly [K in N]: symbol
565 }
566>(codec: C, predicate: Refinement<TypeOf<C>, Branded<TypeOf<C>, B>>, name: N): BrandC<C, B>
567/**
568 * @since 1.8.1
569 */
570export interface IntBrand {
571 readonly Int: unique symbol
572}
573/**
574 * A branded codec representing an integer
575 *
576 * @category primitives
577 * @since 1.8.1
578 */
579export declare const Int: BrandC<NumberC, IntBrand>
580/**
581 * @since 1.8.1
582 */
583export declare type Int = Branded<number, IntBrand>
584/**
585 * @since 1.0.0
586 */
587export declare class RecursiveType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
588 runDefinition: () => C
589 /**
590 * @since 1.0.0
591 */
592 readonly _tag: 'RecursiveType'
593 constructor(
594 name: string,
595 is: RecursiveType<C, A, O, I>['is'],
596 validate: RecursiveType<C, A, O, I>['validate'],
597 encode: RecursiveType<C, A, O, I>['encode'],
598 runDefinition: () => C
599 )
600 /**
601 * @since 1.0.0
602 */
603 readonly type: C
604}
605/**
606 * @category combinators
607 * @since 1.0.0
608 */
609export declare function recursion<A, O = A, I = unknown, C extends Type<A, O, I> = Type<A, O, I>>(
610 name: string,
611 definition: (self: C) => C
612): RecursiveType<C, A, O, I>
613/**
614 * @since 1.0.0
615 */
616export declare class ArrayType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
617 readonly type: C
618 /**
619 * @since 1.0.0
620 */
621 readonly _tag: 'ArrayType'
622 constructor(
623 name: string,
624 is: ArrayType<C, A, O, I>['is'],
625 validate: ArrayType<C, A, O, I>['validate'],
626 encode: ArrayType<C, A, O, I>['encode'],
627 type: C
628 )
629}
630/**
631 * @since 1.5.3
632 */
633export interface ArrayC<C extends Mixed> extends ArrayType<C, Array<TypeOf<C>>, Array<OutputOf<C>>, unknown> {}
634/**
635 * @category combinators
636 * @since 1.0.0
637 */
638export declare function array<C extends Mixed>(item: C, name?: string): ArrayC<C>
639/**
640 * @since 1.0.0
641 */
642export declare class InterfaceType<P, A = any, O = A, I = unknown> extends Type<A, O, I> {
643 readonly props: P
644 /**
645 * @since 1.0.0
646 */
647 readonly _tag: 'InterfaceType'
648 constructor(
649 name: string,
650 is: InterfaceType<P, A, O, I>['is'],
651 validate: InterfaceType<P, A, O, I>['validate'],
652 encode: InterfaceType<P, A, O, I>['encode'],
653 props: P
654 )
655}
656/**
657 * @since 1.5.3
658 */
659export interface TypeC<P extends Props>
660 extends InterfaceType<
661 P,
662 {
663 [K in keyof P]: TypeOf<P[K]>
664 },
665 {
666 [K in keyof P]: OutputOf<P[K]>
667 },
668 unknown
669 > {}
670/**
671 * @category combinators
672 * @since 1.0.0
673 */
674export declare function type<P extends Props>(props: P, name?: string): TypeC<P>
675/**
676 * @since 1.0.0
677 */
678export declare class PartialType<P, A = any, O = A, I = unknown> extends Type<A, O, I> {
679 readonly props: P
680 /**
681 * @since 1.0.0
682 */
683 readonly _tag: 'PartialType'
684 constructor(
685 name: string,
686 is: PartialType<P, A, O, I>['is'],
687 validate: PartialType<P, A, O, I>['validate'],
688 encode: PartialType<P, A, O, I>['encode'],
689 props: P
690 )
691}
692/**
693 * @since 1.5.3
694 */
695export interface PartialC<P extends Props>
696 extends PartialType<
697 P,
698 {
699 [K in keyof P]?: TypeOf<P[K]>
700 },
701 {
702 [K in keyof P]?: OutputOf<P[K]>
703 },
704 unknown
705 > {}
706/**
707 * @category combinators
708 * @since 1.0.0
709 */
710export declare function partial<P extends Props>(props: P, name?: string): PartialC<P>
711/**
712 * @since 1.0.0
713 */
714export declare class DictionaryType<D extends Any, C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
715 readonly domain: D
716 readonly codomain: C
717 /**
718 * @since 1.0.0
719 */
720 readonly _tag: 'DictionaryType'
721 constructor(
722 name: string,
723 is: DictionaryType<D, C, A, O, I>['is'],
724 validate: DictionaryType<D, C, A, O, I>['validate'],
725 encode: DictionaryType<D, C, A, O, I>['encode'],
726 domain: D,
727 codomain: C
728 )
729}
730/**
731 * @since 1.5.3
732 */
733export interface RecordC<D extends Mixed, C extends Mixed>
734 extends DictionaryType<
735 D,
736 C,
737 {
738 [K in TypeOf<D>]: TypeOf<C>
739 },
740 {
741 [K in OutputOf<D>]: OutputOf<C>
742 },
743 unknown
744 > {}
745/**
746 * @category combinators
747 * @since 1.7.1
748 */
749export declare function record<D extends Mixed, C extends Mixed>(domain: D, codomain: C, name?: string): RecordC<D, C>
750/**
751 * @since 1.0.0
752 */
753export declare class UnionType<CS extends Array<Any>, A = any, O = A, I = unknown> extends Type<A, O, I> {
754 readonly types: CS
755 /**
756 * @since 1.0.0
757 */
758 readonly _tag: 'UnionType'
759 constructor(
760 name: string,
761 is: UnionType<CS, A, O, I>['is'],
762 validate: UnionType<CS, A, O, I>['validate'],
763 encode: UnionType<CS, A, O, I>['encode'],
764 types: CS
765 )
766}
767/**
768 * @since 1.5.3
769 */
770export interface UnionC<CS extends [Mixed, Mixed, ...Array<Mixed>]>
771 extends UnionType<CS, TypeOf<CS[number]>, OutputOf<CS[number]>, unknown> {}
772/**
773 * @category combinators
774 * @since 1.0.0
775 */
776export declare function union<CS extends [Mixed, Mixed, ...Array<Mixed>]>(codecs: CS, name?: string): UnionC<CS>
777/**
778 * @since 1.0.0
779 */
780export declare class IntersectionType<CS extends Array<Any>, A = any, O = A, I = unknown> extends Type<A, O, I> {
781 readonly types: CS
782 /**
783 * @since 1.0.0
784 */
785 readonly _tag: 'IntersectionType'
786 constructor(
787 name: string,
788 is: IntersectionType<CS, A, O, I>['is'],
789 validate: IntersectionType<CS, A, O, I>['validate'],
790 encode: IntersectionType<CS, A, O, I>['encode'],
791 types: CS
792 )
793}
794/**
795 * @since 1.5.3
796 */
797export interface IntersectionC<CS extends [Mixed, Mixed, ...Array<Mixed>]>
798 extends IntersectionType<
799 CS,
800 CS extends {
801 length: 2
802 }
803 ? TypeOf<CS[0]> & TypeOf<CS[1]>
804 : CS extends {
805 length: 3
806 }
807 ? TypeOf<CS[0]> & TypeOf<CS[1]> & TypeOf<CS[2]>
808 : CS extends {
809 length: 4
810 }
811 ? TypeOf<CS[0]> & TypeOf<CS[1]> & TypeOf<CS[2]> & TypeOf<CS[3]>
812 : CS extends {
813 length: 5
814 }
815 ? TypeOf<CS[0]> & TypeOf<CS[1]> & TypeOf<CS[2]> & TypeOf<CS[3]> & TypeOf<CS[4]>
816 : unknown,
817 CS extends {
818 length: 2
819 }
820 ? OutputOf<CS[0]> & OutputOf<CS[1]>
821 : CS extends {
822 length: 3
823 }
824 ? OutputOf<CS[0]> & OutputOf<CS[1]> & OutputOf<CS[2]>
825 : CS extends {
826 length: 4
827 }
828 ? OutputOf<CS[0]> & OutputOf<CS[1]> & OutputOf<CS[2]> & OutputOf<CS[3]>
829 : CS extends {
830 length: 5
831 }
832 ? OutputOf<CS[0]> & OutputOf<CS[1]> & OutputOf<CS[2]> & OutputOf<CS[3]> & OutputOf<CS[4]>
833 : unknown,
834 unknown
835 > {}
836/**
837 * @category combinators
838 * @since 1.0.0
839 */
840export declare function intersection<
841 A extends Mixed,
842 B extends Mixed,
843 C extends Mixed,
844 D extends Mixed,
845 E extends Mixed
846>(codecs: [A, B, C, D, E], name?: string): IntersectionC<[A, B, C, D, E]>
847export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(
848 codecs: [A, B, C, D],
849 name?: string
850): IntersectionC<[A, B, C, D]>
851export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed>(
852 codecs: [A, B, C],
853 name?: string
854): IntersectionC<[A, B, C]>
855export declare function intersection<A extends Mixed, B extends Mixed>(
856 codecs: [A, B],
857 name?: string
858): IntersectionC<[A, B]>
859/**
860 * @since 1.0.0
861 */
862export declare class TupleType<CS extends Array<Any>, A = any, O = A, I = unknown> extends Type<A, O, I> {
863 readonly types: CS
864 /**
865 * @since 1.0.0
866 */
867 readonly _tag: 'TupleType'
868 constructor(
869 name: string,
870 is: TupleType<CS, A, O, I>['is'],
871 validate: TupleType<CS, A, O, I>['validate'],
872 encode: TupleType<CS, A, O, I>['encode'],
873 types: CS
874 )
875}
876/**
877 * @since 1.5.3
878 */
879export interface TupleC<CS extends [Mixed, ...Array<Mixed>]>
880 extends TupleType<
881 CS,
882 CS extends {
883 length: 1
884 }
885 ? [TypeOf<CS[0]>]
886 : CS extends {
887 length: 2
888 }
889 ? [TypeOf<CS[0]>, TypeOf<CS[1]>]
890 : CS extends {
891 length: 3
892 }
893 ? [TypeOf<CS[0]>, TypeOf<CS[1]>, TypeOf<CS[2]>]
894 : CS extends {
895 length: 4
896 }
897 ? [TypeOf<CS[0]>, TypeOf<CS[1]>, TypeOf<CS[2]>, TypeOf<CS[3]>]
898 : CS extends {
899 length: 5
900 }
901 ? [TypeOf<CS[0]>, TypeOf<CS[1]>, TypeOf<CS[2]>, TypeOf<CS[3]>, TypeOf<CS[4]>]
902 : unknown,
903 CS extends {
904 length: 1
905 }
906 ? [OutputOf<CS[0]>]
907 : CS extends {
908 length: 2
909 }
910 ? [OutputOf<CS[0]>, OutputOf<CS[1]>]
911 : CS extends {
912 length: 3
913 }
914 ? [OutputOf<CS[0]>, OutputOf<CS[1]>, OutputOf<CS[2]>]
915 : CS extends {
916 length: 4
917 }
918 ? [OutputOf<CS[0]>, OutputOf<CS[1]>, OutputOf<CS[2]>, OutputOf<CS[3]>]
919 : CS extends {
920 length: 5
921 }
922 ? [OutputOf<CS[0]>, OutputOf<CS[1]>, OutputOf<CS[2]>, OutputOf<CS[3]>, OutputOf<CS[4]>]
923 : unknown,
924 unknown
925 > {}
926/**
927 * @category combinators
928 * @since 1.0.0
929 */
930export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed, E extends Mixed>(
931 codecs: [A, B, C, D, E],
932 name?: string
933): TupleC<[A, B, C, D, E]>
934export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(
935 codecs: [A, B, C, D],
936 name?: string
937): TupleC<[A, B, C, D]>
938export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed>(
939 codecs: [A, B, C],
940 name?: string
941): TupleC<[A, B, C]>
942export declare function tuple<A extends Mixed, B extends Mixed>(codecs: [A, B], name?: string): TupleC<[A, B]>
943export declare function tuple<A extends Mixed>(codecs: [A], name?: string): TupleC<[A]>
944/**
945 * @since 1.0.0
946 */
947export declare class ReadonlyType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
948 readonly type: C
949 /**
950 * @since 1.0.0
951 */
952 readonly _tag: 'ReadonlyType'
953 constructor(
954 name: string,
955 is: ReadonlyType<C, A, O, I>['is'],
956 validate: ReadonlyType<C, A, O, I>['validate'],
957 encode: ReadonlyType<C, A, O, I>['encode'],
958 type: C
959 )
960}
961/**
962 * @since 1.5.3
963 */
964export interface ReadonlyC<C extends Mixed>
965 extends ReadonlyType<C, Readonly<TypeOf<C>>, Readonly<OutputOf<C>>, unknown> {}
966/**
967 * @category combinators
968 * @since 1.0.0
969 */
970export declare function readonly<C extends Mixed>(codec: C, name?: string): ReadonlyC<C>
971/**
972 * @since 1.0.0
973 */
974export declare class ReadonlyArrayType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
975 readonly type: C
976 /**
977 * @since 1.0.0
978 */
979 readonly _tag: 'ReadonlyArrayType'
980 constructor(
981 name: string,
982 is: ReadonlyArrayType<C, A, O, I>['is'],
983 validate: ReadonlyArrayType<C, A, O, I>['validate'],
984 encode: ReadonlyArrayType<C, A, O, I>['encode'],
985 type: C
986 )
987}
988/**
989 * @since 1.5.3
990 */
991export interface ReadonlyArrayC<C extends Mixed>
992 extends ReadonlyArrayType<C, ReadonlyArray<TypeOf<C>>, ReadonlyArray<OutputOf<C>>, unknown> {}
993/**
994 * @category combinators
995 * @since 1.0.0
996 */
997export declare function readonlyArray<C extends Mixed>(item: C, name?: string): ReadonlyArrayC<C>
998/**
999 * Strips additional properties, equivalent to `exact(type(props))`.
1000 *
1001 * @category combinators
1002 * @since 1.0.0
1003 */
1004export declare const strict: <P extends Props>(props: P, name?: string | undefined) => ExactC<TypeC<P>>
1005/**
1006 * @since 1.1.0
1007 */
1008export declare class ExactType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
1009 readonly type: C
1010 /**
1011 * @since 1.0.0
1012 */
1013 readonly _tag: 'ExactType'
1014 constructor(
1015 name: string,
1016 is: ExactType<C, A, O, I>['is'],
1017 validate: ExactType<C, A, O, I>['validate'],
1018 encode: ExactType<C, A, O, I>['encode'],
1019 type: C
1020 )
1021}
1022/**
1023 * @since 1.5.3
1024 */
1025export interface ExactC<C extends HasProps> extends ExactType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {}
1026/**
1027 * Strips additional properties.
1028 *
1029 * @category combinators
1030 * @since 1.1.0
1031 */
1032export declare function exact<C extends HasProps>(codec: C, name?: string): ExactC<C>
1033/**
1034 * @since 1.0.0
1035 * @deprecated
1036 */
1037export declare class FunctionType extends Type<Function> {
1038 /**
1039 * @since 1.0.0
1040 */
1041 readonly _tag: 'FunctionType'
1042 constructor()
1043}
1044/**
1045 * @since 1.5.3
1046 * @deprecated
1047 */
1048export interface FunctionC extends FunctionType {}
1049/**
1050 * @category primitives
1051 * @since 1.0.0
1052 * @deprecated
1053 */
1054export declare const Function: FunctionC
1055/**
1056 * @since 1.3.0
1057 * @deprecated
1058 */
1059export declare class TaggedUnionType<
1060 Tag extends string,
1061 CS extends Array<Mixed>,
1062 A = any,
1063 O = A,
1064 I = unknown
1065> extends UnionType<CS, A, O, I> {
1066 readonly tag: Tag
1067 constructor(
1068 name: string,
1069 is: TaggedUnionType<Tag, CS, A, O, I>['is'],
1070 validate: TaggedUnionType<Tag, CS, A, O, I>['validate'],
1071 encode: TaggedUnionType<Tag, CS, A, O, I>['encode'],
1072 codecs: CS,
1073 tag: Tag
1074 )
1075}
1076/**
1077 * @since 1.5.3
1078 * @deprecated
1079 */
1080export interface TaggedUnionC<Tag extends string, CS extends [Mixed, Mixed, ...Array<Mixed>]> // tslint:disable-next-line: deprecation
1081 extends TaggedUnionType<Tag, CS, TypeOf<CS[number]>, OutputOf<CS[number]>, unknown> {}
1082/**
1083 * Use `union` instead.
1084 *
1085 * @category combinators
1086 * @since 1.3.0
1087 * @deprecated
1088 */
1089export declare const taggedUnion: <Tag extends string, CS extends [Mixed, Mixed, ...Mixed[]]>(
1090 tag: Tag,
1091 codecs: CS,
1092 name?: string
1093) => TaggedUnionC<Tag, CS>
1094export {
1095 /**
1096 * Use `UnknownArray` instead.
1097 *
1098 * @category primitives
1099 * @deprecated
1100 * @since 1.0.0
1101 */
1102 UnknownArray as Array
1103}
1104export {
1105 /**
1106 * Use `type` instead.
1107 *
1108 * @category combinators
1109 * @deprecated
1110 * @since 1.0.0
1111 */
1112 type as interface
1113}
1114/**
1115 * Use `unknown` instead.
1116 *
1117 * @since 1.0.0
1118 * @deprecated
1119 */
1120export declare type mixed = unknown
1121/**
1122 * @since 1.0.0
1123 * @deprecated
1124 */
1125export declare const getValidationError: (value: unknown, context: Context) => ValidationError
1126/**
1127 * @since 1.0.0
1128 * @deprecated
1129 */
1130export declare const getDefaultContext: (decoder: Decoder<any, any>) => Context
1131/**
1132 * @since 1.0.0
1133 * @deprecated
1134 */
1135export declare class NeverType extends Type<never> {
1136 /**
1137 * @since 1.0.0
1138 */
1139 readonly _tag: 'NeverType'
1140 constructor()
1141}
1142/**
1143 * @since 1.5.3
1144 * @deprecated
1145 */
1146export interface NeverC extends NeverType {}
1147/**
1148 * @category primitives
1149 * @since 1.0.0
1150 * @deprecated
1151 */
1152export declare const never: NeverC
1153/**
1154 * @since 1.0.0
1155 * @deprecated
1156 */
1157export declare class AnyType extends Type<any> {
1158 /**
1159 * @since 1.0.0
1160 */
1161 readonly _tag: 'AnyType'
1162 constructor()
1163}
1164/**
1165 * @since 1.5.3
1166 * @deprecated
1167 */
1168export interface AnyC extends AnyType {}
1169/**
1170 * Use `unknown` instead.
1171 *
1172 * @category primitives
1173 * @since 1.0.0
1174 * @deprecated
1175 */
1176export declare const any: AnyC
1177/**
1178 * Use `UnknownRecord` instead.
1179 *
1180 * @category primitives
1181 * @since 1.0.0
1182 * @deprecated
1183 */
1184export declare const Dictionary: UnknownRecordC
1185/**
1186 * @since 1.0.0
1187 * @deprecated
1188 */
1189export declare class ObjectType extends Type<object> {
1190 /**
1191 * @since 1.0.0
1192 */
1193 readonly _tag: 'ObjectType'
1194 constructor()
1195}
1196/**
1197 * @since 1.5.3
1198 * @deprecated
1199 */
1200export interface ObjectC extends ObjectType {}
1201/**
1202 * Use `UnknownRecord` instead.
1203 *
1204 * @category primitives
1205 * @since 1.0.0
1206 * @deprecated
1207 */
1208export declare const object: ObjectC
1209/**
1210 * Use `BrandC` instead.
1211 *
1212 * @since 1.5.3
1213 * @deprecated
1214 */
1215export interface RefinementC<C extends Any> extends RefinementType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {}
1216/**
1217 * Use `brand` instead.
1218 *
1219 * @category combinators
1220 * @since 1.0.0
1221 * @deprecated
1222 */
1223export declare function refinement<C extends Any>(
1224 codec: C,
1225 predicate: Predicate<TypeOf<C>>,
1226 name?: string
1227): RefinementC<C>
1228/**
1229 * Use `Int` instead.
1230 *
1231 * @category primitives
1232 * @since 1.0.0
1233 * @deprecated
1234 */
1235export declare const Integer: RefinementC<NumberC>
1236/**
1237 * Use `record` instead.
1238 *
1239 * @category combinators
1240 * @since 1.0.0
1241 * @deprecated
1242 */
1243export declare const dictionary: typeof record
1244/**
1245 * @since 1.4.2
1246 * @deprecated
1247 */
1248export declare type Compact<A> = {
1249 [K in keyof A]: A[K]
1250}
1251/**
1252 * @since 1.0.0
1253 * @deprecated
1254 */
1255export declare class StrictType<P, A = any, O = A, I = unknown> extends Type<A, O, I> {
1256 readonly props: P
1257 /**
1258 * @since 1.0.0
1259 */
1260 readonly _tag: 'StrictType'
1261 constructor(
1262 name: string,
1263 is: StrictType<P, A, O, I>['is'],
1264 validate: StrictType<P, A, O, I>['validate'],
1265 encode: StrictType<P, A, O, I>['encode'],
1266 props: P
1267 )
1268}
1269/**
1270 * @since 1.5.3
1271 * @deprecated
1272 */
1273export interface StrictC<P extends Props> // tslint:disable-next-line: deprecation
1274 extends StrictType<
1275 P,
1276 {
1277 [K in keyof P]: TypeOf<P[K]>
1278 },
1279 {
1280 [K in keyof P]: OutputOf<P[K]>
1281 },
1282 unknown
1283 > {}
1284/**
1285 * @since 1.3.0
1286 * @deprecated
1287 */
1288export declare type TaggedProps<Tag extends string> = {
1289 [K in Tag]: LiteralType<any>
1290}
1291/**
1292 * @since 1.3.0
1293 * @deprecated
1294 */
1295export interface TaggedRefinement<Tag extends string, A, O = A> extends RefinementType<Tagged<Tag>, A, O> {}
1296/**
1297 * @since 1.3.0
1298 * @deprecated
1299 */
1300export interface TaggedUnion<Tag extends string, A, O = A> extends UnionType<Array<Tagged<Tag>>, A, O> {}
1301/**
1302 * @since 1.3.0
1303 * @deprecated
1304 */
1305export declare type TaggedIntersectionArgument<Tag extends string> =
1306 | [Tagged<Tag>]
1307 | [Tagged<Tag>, Mixed]
1308 | [Mixed, Tagged<Tag>]
1309 | [Tagged<Tag>, Mixed, Mixed]
1310 | [Mixed, Tagged<Tag>, Mixed]
1311 | [Mixed, Mixed, Tagged<Tag>]
1312 | [Tagged<Tag>, Mixed, Mixed, Mixed]
1313 | [Mixed, Tagged<Tag>, Mixed, Mixed]
1314 | [Mixed, Mixed, Tagged<Tag>, Mixed]
1315 | [Mixed, Mixed, Mixed, Tagged<Tag>]
1316 | [Tagged<Tag>, Mixed, Mixed, Mixed, Mixed]
1317 | [Mixed, Tagged<Tag>, Mixed, Mixed, Mixed]
1318 | [Mixed, Mixed, Tagged<Tag>, Mixed, Mixed]
1319 | [Mixed, Mixed, Mixed, Tagged<Tag>, Mixed]
1320 | [Mixed, Mixed, Mixed, Mixed, Tagged<Tag>]
1321/**
1322 * @since 1.3.0
1323 * @deprecated
1324 */
1325export interface TaggedIntersection<Tag extends string, A, O = A> // tslint:disable-next-line: deprecation
1326 extends IntersectionType<TaggedIntersectionArgument<Tag>, A, O> {}
1327/**
1328 * @since 1.3.0
1329 * @deprecated
1330 */
1331export interface TaggedExact<Tag extends string, A, O = A> extends ExactType<Tagged<Tag>, A, O> {}
1332/**
1333 * @since 1.3.0
1334 * @deprecated
1335 */
1336export declare type Tagged<Tag extends string, A = any, O = A> =
1337 | InterfaceType<TaggedProps<Tag>, A, O>
1338 | StrictType<TaggedProps<Tag>, A, O>
1339 | TaggedRefinement<Tag, A, O>
1340 | TaggedUnion<Tag, A, O>
1341 | TaggedIntersection<Tag, A, O>
1342 | TaggedExact<Tag, A, O>
1343 | RecursiveType<any, A, O>
1344/**
1345 * Drops the codec "kind".
1346 *
1347 * @category combinators
1348 * @since 1.1.0
1349 * @deprecated
1350 */
1351export declare function clean<A, O = A, I = unknown>(codec: Type<A, O, I>): Type<A, O, I>
1352/**
1353 * @since 1.0.0
1354 * @deprecated
1355 */
1356export declare type PropsOf<
1357 T extends {
1358 props: any
1359 }
1360> = T['props']
1361/**
1362 * @since 1.1.0
1363 * @deprecated
1364 */
1365export declare type Exact<T, X extends T> = T &
1366 {
1367 [K in ({
1368 [K in keyof X]: K
1369 } &
1370 {
1371 [K in keyof T]: never
1372 } & {
1373 [key: string]: never
1374 })[keyof X]]?: never
1375 }
1376/**
1377 * Keeps the codec "kind".
1378 *
1379 * @category combinators
1380 * @since 1.1.0
1381 * @deprecated
1382 */
1383export declare function alias<A, O, P, I>(
1384 codec: PartialType<P, A, O, I>
1385): <
1386 AA extends Exact<A, AA>,
1387 OO extends Exact<O, OO> = O,
1388 PP extends Exact<P, PP> = P,
1389 II extends I = I
1390>() => PartialType<PP, AA, OO, II>
1391export declare function alias<A, O, P, I>(
1392 codec: StrictType<P, A, O, I>
1393): <
1394 AA extends Exact<A, AA>,
1395 OO extends Exact<O, OO> = O,
1396 PP extends Exact<P, PP> = P,
1397 II extends I = I
1398>() => StrictType<PP, AA, OO, II>
1399export declare function alias<A, O, P, I>(
1400 codec: InterfaceType<P, A, O, I>
1401): <
1402 AA extends Exact<A, AA>,
1403 OO extends Exact<O, OO> = O,
1404 PP extends Exact<P, PP> = P,
1405 II extends I = I
1406>() => InterfaceType<PP, AA, OO, II>
1407
\No newline at end of file