@@ -1402,7 +1402,7 @@ describe('function syntax w/ emits', () => {
1402
1402
describe ( 'function syntax w/ runtime props' , ( ) => {
1403
1403
// with runtime props, the runtime props must match
1404
1404
// manual type declaration
1405
- defineComponent (
1405
+ const Comp1 = defineComponent (
1406
1406
( _props : { msg : string } ) => {
1407
1407
return ( ) => { }
1408
1408
} ,
@@ -1411,7 +1411,34 @@ describe('function syntax w/ runtime props', () => {
1411
1411
} ,
1412
1412
)
1413
1413
1414
+ // @ts -expect-error bar isn't specified in props definition
1414
1415
defineComponent (
1416
+ ( _props : { msg : string } ) => {
1417
+ return ( ) => { }
1418
+ } ,
1419
+ {
1420
+ props : [ 'msg' , 'bar' ] ,
1421
+ } ,
1422
+ )
1423
+
1424
+ defineComponent (
1425
+ ( _props : { msg : string ; bar : string } ) => {
1426
+ return ( ) => { }
1427
+ } ,
1428
+ {
1429
+ props : [ 'msg' ] ,
1430
+ } ,
1431
+ )
1432
+
1433
+ expectType < JSX . Element > ( < Comp1 msg = "1" /> )
1434
+ // @ts -expect-error msg type is incorrect
1435
+ expectType < JSX . Element > ( < Comp1 msg = { 1 } /> )
1436
+ // @ts -expect-error msg is missing
1437
+ expectType < JSX . Element > ( < Comp1 /> )
1438
+ // @ts -expect-error bar doesn't exist
1439
+ expectType < JSX . Element > ( < Comp1 msg = "1" bar = "2" /> )
1440
+
1441
+ const Comp2 = defineComponent (
1415
1442
< T extends string > ( _props : { msg : T } ) => {
1416
1443
return ( ) => { }
1417
1444
} ,
@@ -1420,7 +1447,36 @@ describe('function syntax w/ runtime props', () => {
1420
1447
} ,
1421
1448
)
1422
1449
1450
+ // @ts -expect-error bar isn't specified in props definition
1423
1451
defineComponent (
1452
+ < T extends string > ( _props : { msg : T } ) => {
1453
+ return ( ) => { }
1454
+ } ,
1455
+ {
1456
+ props : [ 'msg' , 'bar' ] ,
1457
+ } ,
1458
+ )
1459
+
1460
+ defineComponent (
1461
+ < T extends string > ( _props : { msg : T ; bar : T } ) => {
1462
+ return ( ) => { }
1463
+ } ,
1464
+ {
1465
+ props : [ 'msg' ] ,
1466
+ } ,
1467
+ )
1468
+
1469
+ expectType < JSX . Element > ( < Comp2 msg = "1" /> )
1470
+ expectType < JSX . Element > ( < Comp2 < string > msg = "1" /> )
1471
+ // @ts -expect-error msg type is incorrect
1472
+ expectType < JSX . Element > ( < Comp2 msg = { 1 } /> )
1473
+ // @ts -expect-error msg is missing
1474
+ expectType < JSX . Element > ( < Comp2 /> )
1475
+ // @ts -expect-error bar doesn't exist
1476
+ expectType < JSX . Element > ( < Comp2 msg = "1" bar = "2" /> )
1477
+
1478
+ // Note: generics aren't supported with object runtime props
1479
+ const Comp3 = defineComponent (
1424
1480
< T extends string > ( _props : { msg : T } ) => {
1425
1481
return ( ) => { }
1426
1482
} ,
@@ -1431,37 +1487,58 @@ describe('function syntax w/ runtime props', () => {
1431
1487
} ,
1432
1488
)
1433
1489
1434
- // @ts -expect-error string prop names don't match
1435
1490
defineComponent (
1436
- ( _props : { msg : string } ) => {
1491
+ // @ts -expect-error bar isn't specified in props definition
1492
+ < T extends string > ( _props : { msg : T } ) => {
1437
1493
return ( ) => { }
1438
1494
} ,
1439
1495
{
1440
- props : [ 'bar' ] ,
1496
+ props : {
1497
+ bar : String ,
1498
+ } ,
1441
1499
} ,
1442
1500
)
1443
1501
1444
1502
defineComponent (
1445
- ( _props : { msg : string } ) => {
1503
+ // @ts -expect-error generics aren't supported with object runtime props
1504
+ < T extends string > ( _props : { msg : T ; bar : T } ) => {
1446
1505
return ( ) => { }
1447
1506
} ,
1448
1507
{
1449
1508
props : {
1450
- // @ts -expect-error prop type mismatch
1451
- msg : Number ,
1509
+ msg : String ,
1452
1510
} ,
1453
1511
} ,
1454
1512
)
1455
1513
1456
- // @ts -expect-error prop keys don't match
1514
+ expectType < JSX . Element > ( < Comp3 msg = "1" /> )
1515
+ // @ts -expect-error generics aren't supported with object runtime props
1516
+ expectType < JSX . Element > ( < Comp3 < string > msg = "1" /> )
1517
+ // @ts -expect-error msg type is incorrect
1518
+ expectType < JSX . Element > ( < Comp3 msg = { 1 } /> )
1519
+ // @ts -expect-error msg is missing
1520
+ expectType < JSX . Element > ( < Comp3 /> )
1521
+ // @ts -expect-error bar doesn't exist
1522
+ expectType < JSX . Element > ( < Comp3 msg = "1" bar = "2" /> )
1523
+
1524
+ // @ts -expect-error string prop names don't match
1457
1525
defineComponent (
1458
- ( _props : { msg : string } , ctx ) => {
1526
+ ( _props : { msg : string } ) => {
1527
+ return ( ) => { }
1528
+ } ,
1529
+ {
1530
+ props : [ 'bar' ] ,
1531
+ } ,
1532
+ )
1533
+
1534
+ defineComponent (
1535
+ ( _props : { msg : string } ) => {
1459
1536
return ( ) => { }
1460
1537
} ,
1461
1538
{
1462
1539
props : {
1463
- msg : String ,
1464
- bar : String ,
1540
+ // @ts -expect-error prop type mismatch
1541
+ msg : Number ,
1465
1542
} ,
1466
1543
} ,
1467
1544
)
0 commit comments