@@ -72,11 +72,29 @@ describe('<Slot /> typing', () => {
7272 return info . name ;
7373 }
7474
75+ it ( 'should infer whether the schema is requested' , ( ) => {
76+ const code : CodeOptions = {
77+ code : `
78+ <Slot id={'home-banner'} initial={true} includeSchema>
79+ {(params) => typeof params.metadata}
80+ </Slot>;
81+ ` ,
82+ mapping : true ,
83+ } ;
84+
85+ expect ( ( ) => compileCode ( code ) ) . not . toThrow ( ) ;
86+
87+ expect ( getParameterType ( code ) ) . toBe (
88+ 'FetchResponse<boolean | HomeBannerV1, '
89+ + '{children: {};id: "home-banner";initial: boolean;includeSchema: true;}>' ,
90+ ) ;
91+ } ) ;
92+
7593 it ( 'should allow a renderer that accepts JSON objects or covariants for unmapped slots' , ( ) => {
7694 const code : CodeOptions = {
7795 code : `
7896 <Slot id={'home-banner'}>
79- {(params: {foo: string}) => typeof params}
97+ {(params: {content: { foo: string}} ) => typeof params.content }
8098 </Slot>;
8199 ` ,
82100 mapping : false ,
@@ -89,7 +107,7 @@ describe('<Slot /> typing', () => {
89107 const code : CodeOptions = {
90108 code : `
91109 <Slot id={'home-banner'}>
92- {(params: true) => typeof params}
110+ {(params: {content: true} ) => typeof params.content }
93111 </Slot>;
94112 ` ,
95113 mapping : false ,
@@ -102,7 +120,7 @@ describe('<Slot /> typing', () => {
102120 const code : CodeOptions = {
103121 code : `
104122 <Slot id={'home-banner'} initial={true}>
105- {(params: {foo: string}|boolean) => typeof params}
123+ {(params: {content: { foo: string}|boolean} ) => typeof params.content }
106124 </Slot>;
107125 ` ,
108126 mapping : false ,
@@ -115,7 +133,7 @@ describe('<Slot /> typing', () => {
115133 const code : CodeOptions = {
116134 code : `
117135 <Slot id={'home-banner'} initial={true}>
118- {(params: {foo: string}) => typeof params}
136+ {(params: {content: { foo: string}} ) => typeof params.content }
119137 </Slot>;
120138 ` ,
121139 mapping : false ,
@@ -128,7 +146,7 @@ describe('<Slot /> typing', () => {
128146 const code : CodeOptions = {
129147 code : `
130148 <Slot id={'home-banner'} fallback={true}>
131- {(params: {foo: string}|boolean) => typeof params}
149+ {(params: {content: { foo: string}|boolean} ) => typeof params.content }
132150 </Slot>;
133151 ` ,
134152 mapping : false ,
@@ -141,7 +159,7 @@ describe('<Slot /> typing', () => {
141159 const code : CodeOptions = {
142160 code : `
143161 <Slot id={'home-banner'} fallback={true}>
144- {(params: {foo: string}) => typeof params}
162+ {(params: {content: { foo: string}} ) => typeof params.content }
145163 </Slot>;
146164 ` ,
147165 mapping : false ,
@@ -154,7 +172,7 @@ describe('<Slot /> typing', () => {
154172 const code : CodeOptions = {
155173 code : `
156174 <Slot id={'home-banner'} initial={true} fallback={1}>
157- {(params: {foo: string}|boolean|number) => typeof params}
175+ {(params: {content: { foo: string}|boolean|number} ) => typeof params.content }
158176 </Slot>;
159177 ` ,
160178 mapping : false ,
@@ -167,7 +185,7 @@ describe('<Slot /> typing', () => {
167185 const code : CodeOptions = {
168186 code : `
169187 <Slot id={'home-banner'} initial={true} fallback={1}>
170- {(params: {foo: string}|boolean) => typeof params}
188+ {(params: {content: { foo: string}|boolean} ) => typeof params.content }
171189 </Slot>;
172190 ` ,
173191 mapping : false ,
@@ -180,7 +198,7 @@ describe('<Slot /> typing', () => {
180198 const code : CodeOptions = {
181199 code : `
182200 <Slot id={'home-banner'} initial={true} fallback={1}>
183- {(params: {foo: string}|number) => typeof params}
201+ {(params: {content: { foo: string}|number} ) => typeof params.content }
184202 </Slot>;
185203 ` ,
186204 mapping : false ,
@@ -201,14 +219,14 @@ describe('<Slot /> typing', () => {
201219
202220 expect ( ( ) => compileCode ( code ) ) . not . toThrow ( ) ;
203221
204- expect ( getParameterType ( code ) ) . toBe ( 'HomeBannerV1' ) ;
222+ expect ( getParameterType ( code ) ) . toBe ( 'FetchResponse< HomeBannerV1, FetchResponseOptions> ' ) ;
205223 } ) ;
206224
207225 it ( 'should allow a covariant renderer parameter type for mapped slots' , ( ) => {
208226 const code : CodeOptions = {
209227 code : `
210228 <Slot id={'home-banner'}>
211- {(params: {title: string}) => typeof params}
229+ {(params: {content: { title: string} }) => typeof params}
212230 </Slot>;
213231 ` ,
214232 mapping : true ,
@@ -221,7 +239,7 @@ describe('<Slot /> typing', () => {
221239 const code : CodeOptions = {
222240 code : `
223241 <Slot id={'home-banner'}>
224- {(params: {foo: string}) => typeof params}
242+ {(params: {content: { foo: string} }) => typeof params}
225243 </Slot>;
226244 ` ,
227245 mapping : true ,
@@ -242,14 +260,14 @@ describe('<Slot /> typing', () => {
242260
243261 expect ( ( ) => compileCode ( code ) ) . not . toThrow ( ) ;
244262
245- expect ( getParameterType ( code ) ) . toBe ( 'boolean | HomeBannerV1' ) ;
263+ expect ( getParameterType ( code ) ) . toBe ( 'FetchResponse< boolean | HomeBannerV1, FetchResponseOptions> ' ) ;
246264 } ) ;
247265
248266 it ( 'should allow a renderer that accepts the initial value for mapped slots' , ( ) => {
249267 const code : CodeOptions = {
250268 code : `
251269 <Slot id={'home-banner'} initial={true}>
252- {(params: {title: string}|boolean) => typeof params}
270+ {(params: {content: { title: string}|boolean} ) => typeof params.content }
253271 </Slot>;
254272 ` ,
255273 mapping : true ,
@@ -262,7 +280,7 @@ describe('<Slot /> typing', () => {
262280 const code : CodeOptions = {
263281 code : `
264282 <Slot id={'home-banner'} initial={true}>
265- {(params: {title: string}) => typeof params}
283+ {(params: {content: { title: string}} ) => typeof params.content }
266284 </Slot>;
267285 ` ,
268286 mapping : true ,
@@ -283,14 +301,14 @@ describe('<Slot /> typing', () => {
283301
284302 expect ( ( ) => compileCode ( code ) ) . not . toThrow ( ) ;
285303
286- expect ( getParameterType ( code ) ) . toBe ( 'boolean | HomeBannerV1' ) ;
304+ expect ( getParameterType ( code ) ) . toBe ( 'FetchResponse< boolean | HomeBannerV1, FetchResponseOptions> ' ) ;
287305 } ) ;
288306
289307 it ( 'should allow a renderer that accepts the fallback value for mapped slots' , ( ) => {
290308 const code : CodeOptions = {
291309 code : `
292310 <Slot id={'home-banner'} fallback={true}>
293- {(params: {title: string}|boolean) => typeof params}
311+ {(params: {content: { title: string}|boolean} ) => typeof params.content }
294312 </Slot>;
295313 ` ,
296314 mapping : true ,
@@ -303,7 +321,7 @@ describe('<Slot /> typing', () => {
303321 const code : CodeOptions = {
304322 code : `
305323 <Slot id={'home-banner'} fallback={true}>
306- {(params: {title: string}) => typeof params}
324+ {(params: {content: { title: string}} ) => typeof params.content }
307325 </Slot>;
308326 ` ,
309327 mapping : true ,
@@ -324,14 +342,14 @@ describe('<Slot /> typing', () => {
324342
325343 expect ( ( ) => compileCode ( code ) ) . not . toThrow ( ) ;
326344
327- expect ( getParameterType ( code ) ) . toBe ( 'number | boolean | HomeBannerV1' ) ;
345+ expect ( getParameterType ( code ) ) . toBe ( 'FetchResponse< number | boolean | HomeBannerV1, FetchResponseOptions> ' ) ;
328346 } ) ;
329347
330348 it ( 'should allow a renderer that accepts both the initial and fallback values for mapped slots' , ( ) => {
331349 const code : CodeOptions = {
332350 code : `
333351 <Slot id={'home-banner'} initial={true} fallback={1}>
334- {(params: {title: string}|boolean|number) => typeof params}
352+ {(params: {content: { title: string}|boolean|number} ) => typeof params.content }
335353 </Slot>;
336354 ` ,
337355 mapping : true ,
@@ -344,7 +362,7 @@ describe('<Slot /> typing', () => {
344362 const code : CodeOptions = {
345363 code : `
346364 <Slot id={'home-banner'} initial={true} fallback={1}>
347- {(params: {title: string}|boolean) => typeof params}
365+ {(params: {content: { title: string}|boolean} ) => typeof params.content }
348366 </Slot>;
349367 ` ,
350368 mapping : true ,
@@ -357,7 +375,7 @@ describe('<Slot /> typing', () => {
357375 const code : CodeOptions = {
358376 code : `
359377 <Slot id={'home-banner'} initial={true} fallback={1}>
360- {(params: {title: string}|number) => typeof params}
378+ {(params: {content: { title: string}|number} ) => typeof params.content }
361379 </Slot>;
362380 ` ,
363381 mapping : true ,
0 commit comments