88contextualize ( ( ) => {
99 it ( "type array" , ( ) => {
1010 const t = jsonSchemaToType ( { type : "array" } )
11+ attest < unknown [ ] > ( t . infer )
1112 attest ( t . expression ) . snap ( "Array" )
1213 } )
1314
@@ -16,12 +17,14 @@ contextualize(() => {
1617 type : "array" ,
1718 items : { type : "string" }
1819 } )
20+ attest < string [ ] > ( tItems . infer )
1921 attest ( tItems . expression ) . snap ( "string[]" )
2022
2123 const tItemsArr = jsonSchemaToType ( {
2224 type : "array" ,
2325 items : [ { type : "string" } , { type : "number" } ]
2426 } )
27+ attest < [ string , number ] > ( tItemsArr . infer )
2528 attest ( tItemsArr . expression ) . snap ( "[string, number]" )
2629 } )
2730
@@ -30,17 +33,33 @@ contextualize(() => {
3033 type : "array" ,
3134 prefixItems : [ { type : "string" } , { type : "number" } ]
3235 } )
36+ attest < [ string , number , ...unknown [ ] ] > ( tPrefixItems . infer )
3337 attest ( tPrefixItems . expression ) . snap ( "[string, number, ...unknown[]]" )
3438 } )
3539
3640 it ( "items & prefixItems" , ( ) => {
41+ const tItemsFalseAndPrefixItems = jsonSchemaToType ( {
42+ type : "array" ,
43+ prefixItems : [ { type : "string" } , { type : "number" } ] ,
44+ items : false
45+ } )
46+ attest < [ string , number ] > ( tItemsFalseAndPrefixItems . infer )
47+
3748 const tItemsAndPrefixItems = jsonSchemaToType ( {
3849 type : "array" ,
3950 prefixItems : [ { type : "string" } , { type : "number" } ] ,
4051 items : { type : "boolean" }
4152 } )
42- attest ( tItemsAndPrefixItems . expression ) . snap (
43- "[string, number, ...boolean[]]"
53+ attest < [ string , number , ...boolean [ ] ] > ( tItemsAndPrefixItems . infer )
54+
55+ const tItemsArrayAndPrefixItems = jsonSchemaToType ( {
56+ type : "array" ,
57+ prefixItems : [ { type : "string" } , { type : "number" } ] ,
58+ items : [ { type : "boolean" } , { type : "null" } ]
59+ } )
60+ attest < [ string , number , boolean , null ] > ( tItemsArrayAndPrefixItems . infer )
61+ attest ( tItemsArrayAndPrefixItems . expression ) . snap (
62+ "[string, number, boolean, null]"
4463 )
4564 } )
4665
@@ -49,6 +68,7 @@ contextualize(() => {
4968 type : "array" ,
5069 additionalItems : { type : "string" }
5170 } )
71+ attest < string [ ] > ( tAdditionalItems . infer )
5272 attest ( tAdditionalItems . expression ) . snap ( "string[]" )
5373 } )
5474
@@ -58,21 +78,25 @@ contextualize(() => {
5878 additionalItems : { type : "boolean" } ,
5979 items : [ { type : "string" } , { type : "number" } ]
6080 } )
81+ attest < [ string , number , ...boolean [ ] ] > ( tItemsVariadic . infer )
6182 attest ( tItemsVariadic . expression ) . snap ( "[string, number, ...boolean[]]" )
6283
6384 const tItemsFalseAdditional = jsonSchemaToType ( {
6485 type : "array" ,
6586 additionalItems : false ,
6687 items : [ { type : "string" } ]
6788 } )
89+ attest < [ string ] > ( tItemsFalseAdditional . infer )
6890 attest ( tItemsFalseAdditional . expression ) . snap ( "[string]" )
6991
70- attest ( ( ) =>
71- jsonSchemaToType ( {
72- type : "array" ,
73- additionalItems : { type : "string" } ,
74- items : { type : "string" }
75- } )
92+ attest (
93+ ( ) =>
94+ // @ts -expect-error
95+ jsonSchemaToType ( {
96+ type : "array" ,
97+ additionalItems : { type : "string" } ,
98+ items : { type : "string" }
99+ } ) as never
76100 ) . throws ( writeJsonSchemaArrayNonArrayItemsAndAdditionalItemsMessage ( ) )
77101 } )
78102
@@ -88,13 +112,14 @@ contextualize(() => {
88112 } )
89113
90114 it ( "additionalItems & items & prefixItems" , ( ) => {
91- attest ( ( ) =>
92- jsonSchemaToType ( {
93- type : "array" ,
94- additionalItems : { type : "boolean" } ,
95- items : { type : "null" } ,
96- prefixItems : [ { type : "string" } , { type : "number" } ]
97- } )
115+ attest (
116+ ( ) =>
117+ jsonSchemaToType ( {
118+ type : "array" ,
119+ additionalItems : { type : "boolean" } ,
120+ items : { type : "null" } ,
121+ prefixItems : [ { type : "string" } , { type : "number" } ]
122+ } ) as never
98123 ) . throws ( writeJsonSchemaArrayAdditionalItemsAndItemsAndPrefixItemsMessage ( ) )
99124 } )
100125
@@ -103,6 +128,7 @@ contextualize(() => {
103128 type : "array" ,
104129 contains : { type : "number" }
105130 } )
131+ attest < unknown [ ] > ( tContains . infer )
106132 attest ( tContains . json ) . snap ( {
107133 proto : "Array" ,
108134 predicate : [ "$ark.jsonSchemaArrayContainsValidator" ]
@@ -117,27 +143,29 @@ contextualize(() => {
117143 type : "array" ,
118144 maxItems : 5
119145 } )
146+ attest < unknown [ ] > ( tMaxItems . infer )
120147 attest ( tMaxItems . expression ) . snap ( "Array <= 5" )
121148 } )
122149
123150 it ( "maxItems (negative)" , ( ) => {
124- attest ( ( ) => jsonSchemaToType ( { type : "array" , maxItems : - 1 } ) ) . throws (
125- "TraversalError: maxItems must be non-negative"
126- )
151+ attest (
152+ ( ) => jsonSchemaToType ( { type : "array" , maxItems : - 1 } ) as never
153+ ) . throws ( "TraversalError: maxItems must be non-negative" )
127154 } )
128155
129156 it ( "minItems (positive)" , ( ) => {
130157 const tMinItems = jsonSchemaToType ( {
131158 type : "array" ,
132159 minItems : 5
133160 } )
161+ attest < unknown [ ] > ( tMinItems . infer )
134162 attest ( tMinItems . expression ) . snap ( "Array >= 5" )
135163 } )
136164
137165 it ( "minItems (negative)" , ( ) => {
138- attest ( ( ) => jsonSchemaToType ( { type : "array" , minItems : - 1 } ) ) . throws (
139- "TraversalError: minItems must be non-negative"
140- )
166+ attest (
167+ ( ) => jsonSchemaToType ( { type : "array" , minItems : - 1 } ) as never
168+ ) . throws ( "TraversalError: minItems must be non-negative" )
141169 } )
142170
143171 it ( "minItems (0)" , ( ) => {
@@ -155,6 +183,7 @@ contextualize(() => {
155183 type : "array" ,
156184 uniqueItems : true
157185 } )
186+ attest < unknown [ ] > ( tUniqueItems . infer )
158187 attest ( tUniqueItems . json ) . snap ( {
159188 proto : "Array" ,
160189 predicate : [ "$ark.jsonSchemaArrayUniqueItemsValidator" ]
0 commit comments