@@ -100,6 +100,13 @@ describe('"arr" kind', () => {
100100 const arr1 : T1 = [ 'foo' , 1 ] satisfies [ string , number ] ;
101101 const arr2 : [ string , number ] = [ 'foo' , 1 ] satisfies T1 ;
102102 } ) ;
103+
104+ test ( 'named tuple members' , ( ) => {
105+ const schema1 = s . Tuple ( [ s . Key ( 'foo' , s . str ) , s . num ] ) ;
106+ type T1 = TypeOf < typeof schema1 > ;
107+ const arr1 : T1 = [ 'foo' , 1 ] satisfies [ string , number ] ;
108+ const arr2 : [ string , number ] = [ 'foo' , 1 ] satisfies T1 ;
109+ } ) ;
103110} ) ;
104111
105112test ( 'can infer a simple "const" type' , ( ) => {
@@ -127,11 +134,11 @@ test('can infer a simple "tuple" type', () => {
127134
128135test ( 'can infer a simple "obj" type' , ( ) => {
129136 const schema1 = s . obj ;
130- const schema2 = s . Object ( s . prop ( 'foo' , s . str ) , s . propOpt ( 'bar' , s . num ) ) ;
137+ const schema2 = s . Object ( s . Key ( 'foo' , s . str ) , s . KeyOpt ( 'bar' , s . num ) ) ;
131138 const schema3 = s . Object ( {
132- keys : < const > [ s . prop ( 'bar' , s . bool ) ] ,
139+ keys : < const > [ s . Key ( 'bar' , s . bool ) ] ,
133140 } ) ;
134- const schema4 = s . Object ( [ s . prop ( 'baz' , s . num ) , s . propOpt ( 'bazOptional' , s . bool ) , s . propOpt ( 'z' , s . str ) ] , { } ) ;
141+ const schema4 = s . Object ( [ s . Key ( 'baz' , s . num ) , s . KeyOpt ( 'bazOptional' , s . bool ) , s . KeyOpt ( 'z' , s . str ) ] , { } ) ;
135142 type T1 = TypeOf < typeof schema1 > ;
136143 type T2 = TypeOf < typeof schema2 > ;
137144 type T3 = TypeOf < typeof schema3 > ;
@@ -174,7 +181,7 @@ test('can infer a simple "or" type', () => {
174181
175182test ( 'can infer a simple "ref" type' , ( ) => {
176183 const schema1 = s . str ;
177- const schema2 = s . Object ( s . prop ( 'foo' , s . Ref < typeof schema1 > ( 'another-str' ) ) ) ;
184+ const schema2 = s . Object ( s . Key ( 'foo' , s . Ref < typeof schema1 > ( 'another-str' ) ) ) ;
178185 type T1 = TypeOf < typeof schema1 > ;
179186 type T2 = TypeOf < typeof schema2 > ;
180187 const val1 : T1 = 'foo' ;
@@ -204,9 +211,9 @@ test('can infer a simple "fn$" type', () => {
204211} ) ;
205212
206213test ( 'can infer a complex "fn" type' , ( ) => {
207- const arr = s . Array ( s . Object ( s . prop ( 'op' , s . str ) , s . prop ( 'path' , s . str ) ) ) ;
208- const req = s . Object ( s . prop ( 'id' , s . str ) , s . prop ( 'age' , s . num ) , s . prop ( 'patch' , s . Object ( s . prop ( 'ops' , arr ) ) ) ) ;
209- const res = s . Object ( s . prop ( 'id' , s . String ( ) ) ) ;
214+ const arr = s . Array ( s . Object ( s . Key ( 'op' , s . str ) , s . Key ( 'path' , s . str ) ) ) ;
215+ const req = s . Object ( s . Key ( 'id' , s . str ) , s . Key ( 'age' , s . num ) , s . Key ( 'patch' , s . Object ( s . Key ( 'ops' , arr ) ) ) ) ;
216+ const res = s . Object ( s . Key ( 'id' , s . String ( ) ) ) ;
210217 const schema1 = s . Function ( req , res ) ;
211218 type T1 = TypeOf < typeof schema1 > ;
212219 const val1 : T1 = async ( { patch, id} ) => {
@@ -217,12 +224,12 @@ test('can infer a complex "fn" type', () => {
217224
218225test ( 'can infer a realistic schema' , ( ) => {
219226 const schema = s . Object (
220- s . prop ( 'id' , s . str ) ,
221- s . prop ( 'age' , s . num ) ,
222- s . prop ( 'tags' , s . Array ( s . Or ( s . str , s . num ) ) ) ,
223- s . prop ( 'data' , s . Object ( s . prop ( 'foo' , s . str ) , s . prop ( 'bar' , s . num ) ) ) ,
224- s . prop ( 'approved' , s . bool ) ,
225- s . prop ( 'meta' , s . any ) ,
227+ s . Key ( 'id' , s . str ) ,
228+ s . Key ( 'age' , s . num ) ,
229+ s . Key ( 'tags' , s . Array ( s . Or ( s . str , s . num ) ) ) ,
230+ s . Key ( 'data' , s . Object ( s . Key ( 'foo' , s . str ) , s . Key ( 'bar' , s . num ) ) ) ,
231+ s . Key ( 'approved' , s . bool ) ,
232+ s . Key ( 'meta' , s . any ) ,
226233 ) ;
227234 type T = TypeOf < typeof schema > ;
228235 const val : T = {
@@ -239,7 +246,7 @@ test('can infer a realistic schema', () => {
239246} ) ;
240247
241248test ( 'can specify an optional fields' , ( ) => {
242- const schema = s . Object ( s . propOpt ( 'meta' , s . Object ( s . prop ( 'foo' , s . str ) , s . propOpt ( 'bar' , s . num ) ) ) ) ;
249+ const schema = s . Object ( s . KeyOpt ( 'meta' , s . Object ( s . Key ( 'foo' , s . str ) , s . KeyOpt ( 'bar' , s . num ) ) ) ) ;
243250 type T = TypeOf < typeof schema > ;
244251 const val0 : T = { } ;
245252 const val1 : T = {
0 commit comments