File tree 2 files changed +42
-0
lines changed
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -265,6 +265,27 @@ describe('resolveType', () => {
265
265
} )
266
266
} )
267
267
268
+ test ( 'utility type: ReadonlyArray' , ( ) => {
269
+ expect (
270
+ resolve ( `
271
+ defineProps<{ foo: ReadonlyArray<string> }>()
272
+ ` ) . props ,
273
+ ) . toStrictEqual ( {
274
+ foo : [ 'Array' ] ,
275
+ } )
276
+ } )
277
+
278
+ test ( 'utility type: ReadonlyMap & Readonly Set' , ( ) => {
279
+ expect (
280
+ resolve ( `
281
+ defineProps<{ foo: ReadonlyMap<string, unknown>, bar: ReadonlySet<string> }>()
282
+ ` ) . props ,
283
+ ) . toStrictEqual ( {
284
+ foo : [ 'Map' ] ,
285
+ bar : [ 'Set' ] ,
286
+ } )
287
+ } )
288
+
268
289
test ( 'indexed access type (literal)' , ( ) => {
269
290
expect (
270
291
resolve ( `
@@ -416,6 +437,16 @@ describe('resolveType', () => {
416
437
} )
417
438
} )
418
439
440
+ test ( 'readonly' , ( ) => {
441
+ expect (
442
+ resolve ( `
443
+ defineProps<{ foo: readonly unknown[] }>()
444
+ ` ) . props ,
445
+ ) . toStrictEqual ( {
446
+ foo : [ 'Array' ] ,
447
+ } )
448
+ } )
449
+
419
450
test ( 'ExtractPropTypes (element-plus)' , ( ) => {
420
451
const { props, raw } = resolve (
421
452
`
Original file line number Diff line number Diff line change @@ -1547,8 +1547,14 @@ export function inferRuntimeType(
1547
1547
1548
1548
case 'Parameters' :
1549
1549
case 'ConstructorParameters' :
1550
+ case 'ReadonlyArray' :
1550
1551
return [ 'Array' ]
1551
1552
1553
+ case 'ReadonlyMap' :
1554
+ return [ 'Map' ]
1555
+ case 'ReadonlySet' :
1556
+ return [ 'Set' ]
1557
+
1552
1558
case 'NonNullable' :
1553
1559
if ( node . typeParameters && node . typeParameters . params [ 0 ] ) {
1554
1560
return inferRuntimeType (
@@ -1633,6 +1639,11 @@ export function inferRuntimeType(
1633
1639
}
1634
1640
break
1635
1641
}
1642
+
1643
+ // e.g. readonly
1644
+ case 'TSTypeOperator' : {
1645
+ return inferRuntimeType ( ctx , node . typeAnnotation , scope )
1646
+ }
1636
1647
}
1637
1648
} catch ( e ) {
1638
1649
// always soft fail on failed runtime type inference
You can’t perform that action at this time.
0 commit comments