@@ -14,6 +14,27 @@ export type Output<T> = T extends Schema<infer Output, unknown>
1414export type Input < T > = T extends Schema < unknown , infer Input > ? Input : never ;
1515
1616type UnknownSchema = Schema < unknown > ;
17+
18+ type UnknownToOuput < T > = T extends Schema < unknown >
19+ ? Output < T >
20+ : T extends {
21+ [ k in keyof T ] : unknown ;
22+ }
23+ ? {
24+ [ k in keyof T ] : UnknownToOuput < T [ k ] > ;
25+ }
26+ : T ;
27+
28+ type UnknownToInput < T > = T extends Schema < unknown >
29+ ? Input < T >
30+ : T extends {
31+ [ k in keyof T ] : unknown ;
32+ }
33+ ? {
34+ [ k in keyof T ] : UnknownToInput < T [ k ] > ;
35+ }
36+ : T ;
37+
1738type SchemaTupleOutput <
1839 Tuple extends UnknownSchema [ ] ,
1940 Length extends number = Tuple [ "length" ]
@@ -47,6 +68,47 @@ type _TupleInput<
4768 ? Accumulated
4869 : _TupleInput < Tuple , Length , [ ...Accumulated , Input < Tuple [ Index ] > ] > ;
4970
71+ type SchemaUnionTupleOutput <
72+ Tuple extends unknown [ ] ,
73+ Length extends number = Tuple [ "length" ]
74+ > = Length extends Length
75+ ? number extends Length
76+ ? Tuple
77+ : _UnionTupleOutput < Tuple , Length , [ ] >
78+ : never ;
79+ type _UnionTupleOutput <
80+ Tuple extends unknown [ ] ,
81+ Length extends number ,
82+ Accumulated extends unknown [ ] ,
83+ Index extends number = Accumulated [ "length" ]
84+ > = Index extends Length
85+ ? Accumulated
86+ : _UnionTupleOutput <
87+ Tuple ,
88+ Length ,
89+ [ ...Accumulated , UnknownToOuput < Tuple [ Index ] > ]
90+ > ;
91+ type SchemaUnionTupleInput <
92+ Tuple extends unknown [ ] ,
93+ Length extends number = Tuple [ "length" ]
94+ > = Length extends Length
95+ ? number extends Length
96+ ? Tuple
97+ : _UnionTupleInput < Tuple , Length , [ ] >
98+ : never ;
99+ type _UnionTupleInput <
100+ Tuple extends unknown [ ] ,
101+ Length extends number ,
102+ Accumulated extends unknown [ ] ,
103+ Index extends number = Accumulated [ "length" ]
104+ > = Index extends Length
105+ ? Accumulated
106+ : _UnionTupleInput <
107+ Tuple ,
108+ Length ,
109+ [ ...Accumulated , UnknownToInput < Tuple [ Index ] > ]
110+ > ;
111+
50112export const string : Schema < string > ;
51113export const boolean : Schema < boolean > ;
52114export const integer : Schema < number > ;
@@ -108,6 +170,7 @@ export function literal(value: undefined): Schema<undefined>;
108170export function literal ( value : null ) : Schema < null > ;
109171export function literal < T > ( value : T ) : Schema < T > ;
110172
173+ // TODO: Deprecate for V9
111174export function tuple ( schemas : [ ] ) : Schema < [ ] > ;
112175export function tuple < Output , Input > (
113176 schemas : [ Schema < Output , Input > ]
@@ -161,33 +224,13 @@ export const jsonString: <Output>(
161224 space ?: number
162225) => Schema < Output , string > ;
163226
164- export const union : < A extends UnknownSchema , B extends UnknownSchema [ ] > (
227+ export const union : < A , B extends unknown [ ] > (
165228 schemas : [ A , ...B ]
166229) => Schema <
167- Output < A > | SchemaTupleOutput < B > [ number ] ,
168- Input < A > | SchemaTupleInput < B > [ number ]
230+ UnknownToOuput < A > | SchemaUnionTupleOutput < B > [ number ] ,
231+ UnknownToInput < A > | SchemaUnionTupleInput < B > [ number ]
169232> ;
170233
171- type UnknownToOuput < T > = T extends Schema < unknown >
172- ? Output < T >
173- : T extends {
174- [ k in keyof T ] : unknown ;
175- }
176- ? {
177- [ k in keyof T ] : UnknownToOuput < T [ k ] > ;
178- }
179- : T ;
180-
181- type UnknownToInput < T > = T extends Schema < unknown >
182- ? Input < T >
183- : T extends {
184- [ k in keyof T ] : unknown ;
185- }
186- ? {
187- [ k in keyof T ] : UnknownToInput < T [ k ] > ;
188- }
189- : T ;
190-
191234/**
192235 * @deprecated Pass the Schema directly instead of using the s.matches method
193236 */
@@ -214,6 +257,9 @@ export function object<Output>(
214257 tag : ( name : string , value : unknown ) => void ;
215258 } ) => Output
216259) : Schema < Output , unknown > ;
260+ /**
261+ * @deprecated Will be removed in V9. Use S.schema instead
262+ */
217263export function object <
218264 Shape extends {
219265 [ k in keyof Shape ] : unknown ;
@@ -388,6 +434,9 @@ export const trim: <Input>(
388434
389435export type UnknownKeys = "Strip" | "Strict" ;
390436
437+ /**
438+ * @deprecated Will be removed in V9
439+ */
391440export function unwrap < Value > ( result : Result < Value > ) : Value ;
392441
393442export type GlobalConfigOverride = {
0 commit comments