File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,38 @@ describe('resolveType', () => {
207
207
} )
208
208
} )
209
209
210
+ test ( 'utility type: Partial' , ( ) => {
211
+ expect (
212
+ resolve ( `
213
+ type T = { foo: number, bar: string }
214
+ defineProps<Partial<T>>()
215
+ ` ) . raw . props
216
+ ) . toMatchObject ( {
217
+ foo : {
218
+ optional : true
219
+ } ,
220
+ bar : {
221
+ optional : true
222
+ }
223
+ } )
224
+ } )
225
+
226
+ test ( 'utility type: Required' , ( ) => {
227
+ expect (
228
+ resolve ( `
229
+ type T = { foo?: number, bar?: string }
230
+ defineProps<Required<T>>()
231
+ ` ) . raw . props
232
+ ) . toMatchObject ( {
233
+ foo : {
234
+ optional : false
235
+ } ,
236
+ bar : {
237
+ optional : false
238
+ }
239
+ } )
240
+ } )
241
+
210
242
test ( 'utility type: Pick' , ( ) => {
211
243
expect (
212
244
resolve ( `
Original file line number Diff line number Diff line change @@ -513,8 +513,20 @@ function resolveBuiltin(
513
513
) : ResolvedElements {
514
514
const t = resolveTypeElements ( ctx , node . typeParameters ! . params [ 0 ] )
515
515
switch ( name ) {
516
- case 'Partial' :
517
- case 'Required' :
516
+ case 'Partial' : {
517
+ const res : ResolvedElements = { props : { } , calls : t . calls }
518
+ Object . keys ( t . props ) . forEach ( key => {
519
+ res . props [ key ] = { ...t . props [ key ] , optional : true }
520
+ } )
521
+ return res
522
+ }
523
+ case 'Required' : {
524
+ const res : ResolvedElements = { props : { } , calls : t . calls }
525
+ Object . keys ( t . props ) . forEach ( key => {
526
+ res . props [ key ] = { ...t . props [ key ] , optional : false }
527
+ } )
528
+ return res
529
+ }
518
530
case 'Readonly' :
519
531
return t
520
532
case 'Pick' : {
You can’t perform that action at this time.
0 commit comments