@@ -14,7 +14,8 @@ import {
14
14
Slots ,
15
15
VNode ,
16
16
ImgHTMLAttributes ,
17
- StyleValue
17
+ StyleValue ,
18
+ ExtractPropsAndEvents
18
19
} from 'vue'
19
20
import { describe , expectType , IsUnion , test } from './utils'
20
21
@@ -1326,8 +1327,7 @@ describe('define attrs', () => {
1326
1327
// @ts -expect-error
1327
1328
expectType < JSX . Element > ( < MyComp foo = "1" bar = { 1 } /> )
1328
1329
} )
1329
-
1330
- test ( 'wrap elements, such as img element (Keep the volar plugin open)' , ( ) => {
1330
+ test ( 'wrap elements' , ( ) => {
1331
1331
const MyImg = defineComponent ( {
1332
1332
props : {
1333
1333
foo : String
@@ -1344,13 +1344,14 @@ describe('define attrs', () => {
1344
1344
expectType < JSX . Element > ( < MyImg class = { 'str' } style = { 'str' } src = { 'str' } /> )
1345
1345
} )
1346
1346
1347
- test ( 'secondary packaging of components' , ( ) => {
1348
- const childProps = {
1349
- foo : String
1350
- }
1351
- type ChildProps = ExtractPropTypes < typeof childProps >
1347
+ test ( 'wrap components' , ( ) => {
1352
1348
const Child = defineComponent ( {
1353
- props : childProps ,
1349
+ props : {
1350
+ foo : String
1351
+ } ,
1352
+ emits : {
1353
+ baz : ( val : number ) => true
1354
+ } ,
1354
1355
render ( ) {
1355
1356
return < div > { this . foo } </ div >
1356
1357
}
@@ -1359,13 +1360,25 @@ describe('define attrs', () => {
1359
1360
props : {
1360
1361
bar : Number
1361
1362
} ,
1362
- attrs : Object as AttrsType < ChildProps > ,
1363
+ attrs : Object as AttrsType < ExtractPropsAndEvents < typeof Child > > ,
1364
+ created ( ) {
1365
+ expectType < unknown > ( this . $attrs . class )
1366
+ expectType < unknown > ( this . $attrs . style )
1367
+ } ,
1363
1368
render ( ) {
1364
1369
return < Child { ...this . $attrs } />
1365
1370
}
1366
1371
} )
1367
1372
expectType < JSX . Element > (
1368
- < Comp class = { 'str' } style = { 'str' } bar = { 1 } foo = { 'str' } />
1373
+ < Comp
1374
+ class = { 'str' }
1375
+ style = { 'str' }
1376
+ bar = { 1 }
1377
+ foo = { 'str' }
1378
+ onBaz = { val => {
1379
+ expectType < number > ( val )
1380
+ } }
1381
+ />
1369
1382
)
1370
1383
} )
1371
1384
} )
0 commit comments