@@ -1373,7 +1373,7 @@ describe('function syntax w/ emits', () => {
1373
1373
describe ( 'function syntax w/ runtime props' , ( ) => {
1374
1374
// with runtime props, the runtime props must match
1375
1375
// manual type declaration
1376
- defineComponent (
1376
+ const Comp1 = defineComponent (
1377
1377
( _props : { msg : string } ) => {
1378
1378
return ( ) => { }
1379
1379
} ,
@@ -1382,7 +1382,34 @@ describe('function syntax w/ runtime props', () => {
1382
1382
} ,
1383
1383
)
1384
1384
1385
+ // @ts -expect-error bar isn't specified in props definition
1385
1386
defineComponent (
1387
+ ( _props : { msg : string } ) => {
1388
+ return ( ) => { }
1389
+ } ,
1390
+ {
1391
+ props : [ 'msg' , 'bar' ] ,
1392
+ } ,
1393
+ )
1394
+
1395
+ defineComponent (
1396
+ ( _props : { msg : string ; bar : string } ) => {
1397
+ return ( ) => { }
1398
+ } ,
1399
+ {
1400
+ props : [ 'msg' ] ,
1401
+ } ,
1402
+ )
1403
+
1404
+ expectType < JSX . Element > ( < Comp1 msg = "1" /> )
1405
+ // @ts -expect-error msg type is incorrect
1406
+ expectType < JSX . Element > ( < Comp1 msg = { 1 } /> )
1407
+ // @ts -expect-error msg is missing
1408
+ expectType < JSX . Element > ( < Comp1 /> )
1409
+ // @ts -expect-error bar doesn't exist
1410
+ expectType < JSX . Element > ( < Comp1 msg = "1" bar = "2" /> )
1411
+
1412
+ const Comp2 = defineComponent (
1386
1413
< T extends string > ( _props : { msg : T } ) => {
1387
1414
return ( ) => { }
1388
1415
} ,
@@ -1391,7 +1418,36 @@ describe('function syntax w/ runtime props', () => {
1391
1418
} ,
1392
1419
)
1393
1420
1421
+ // @ts -expect-error bar isn't specified in props definition
1394
1422
defineComponent (
1423
+ < T extends string > ( _props : { msg : T } ) => {
1424
+ return ( ) => { }
1425
+ } ,
1426
+ {
1427
+ props : [ 'msg' , 'bar' ] ,
1428
+ } ,
1429
+ )
1430
+
1431
+ defineComponent (
1432
+ < T extends string > ( _props : { msg : T ; bar : T } ) => {
1433
+ return ( ) => { }
1434
+ } ,
1435
+ {
1436
+ props : [ 'msg' ] ,
1437
+ } ,
1438
+ )
1439
+
1440
+ expectType < JSX . Element > ( < Comp2 msg = "1" /> )
1441
+ expectType < JSX . Element > ( < Comp2 < string > msg = "1" /> )
1442
+ // @ts -expect-error msg type is incorrect
1443
+ expectType < JSX . Element > ( < Comp2 msg = { 1 } /> )
1444
+ // @ts -expect-error msg is missing
1445
+ expectType < JSX . Element > ( < Comp2 /> )
1446
+ // @ts -expect-error bar doesn't exist
1447
+ expectType < JSX . Element > ( < Comp2 msg = "1" bar = "2" /> )
1448
+
1449
+ // Note: generics aren't supported with object runtime props
1450
+ const Comp3 = defineComponent (
1395
1451
< T extends string > ( _props : { msg : T } ) => {
1396
1452
return ( ) => { }
1397
1453
} ,
@@ -1402,37 +1458,58 @@ describe('function syntax w/ runtime props', () => {
1402
1458
} ,
1403
1459
)
1404
1460
1405
- // @ts -expect-error string prop names don't match
1406
1461
defineComponent (
1407
- ( _props : { msg : string } ) => {
1462
+ // @ts -expect-error bar isn't specified in props definition
1463
+ < T extends string > ( _props : { msg : T } ) => {
1408
1464
return ( ) => { }
1409
1465
} ,
1410
1466
{
1411
- props : [ 'bar' ] ,
1467
+ props : {
1468
+ bar : String ,
1469
+ } ,
1412
1470
} ,
1413
1471
)
1414
1472
1415
1473
defineComponent (
1416
- ( _props : { msg : string } ) => {
1474
+ // @ts -expect-error generics aren't supported with object runtime props
1475
+ < T extends string > ( _props : { msg : T ; bar : T } ) => {
1417
1476
return ( ) => { }
1418
1477
} ,
1419
1478
{
1420
1479
props : {
1421
- // @ts -expect-error prop type mismatch
1422
- msg : Number ,
1480
+ msg : String ,
1423
1481
} ,
1424
1482
} ,
1425
1483
)
1426
1484
1427
- // @ts -expect-error prop keys don't match
1485
+ expectType < JSX . Element > ( < Comp3 msg = "1" /> )
1486
+ // @ts -expect-error generics aren't supported with object runtime props
1487
+ expectType < JSX . Element > ( < Comp3 < string > msg = "1" /> )
1488
+ // @ts -expect-error msg type is incorrect
1489
+ expectType < JSX . Element > ( < Comp3 msg = { 1 } /> )
1490
+ // @ts -expect-error msg is missing
1491
+ expectType < JSX . Element > ( < Comp3 /> )
1492
+ // @ts -expect-error bar doesn't exist
1493
+ expectType < JSX . Element > ( < Comp3 msg = "1" bar = "2" /> )
1494
+
1495
+ // @ts -expect-error string prop names don't match
1428
1496
defineComponent (
1429
- ( _props : { msg : string } , ctx ) => {
1497
+ ( _props : { msg : string } ) => {
1498
+ return ( ) => { }
1499
+ } ,
1500
+ {
1501
+ props : [ 'bar' ] ,
1502
+ } ,
1503
+ )
1504
+
1505
+ defineComponent (
1506
+ ( _props : { msg : string } ) => {
1430
1507
return ( ) => { }
1431
1508
} ,
1432
1509
{
1433
1510
props : {
1434
- msg : String ,
1435
- bar : String ,
1511
+ // @ts -expect-error prop type mismatch
1512
+ msg : Number ,
1436
1513
} ,
1437
1514
} ,
1438
1515
)
0 commit comments