@@ -14,7 +14,8 @@ import {
1414 Slots ,
1515 VNode ,
1616 ImgHTMLAttributes ,
17- StyleValue
17+ StyleValue ,
18+ ExtractPropsAndEvents
1819} from 'vue'
1920import { describe , expectType , IsUnion , test } from './utils'
2021
@@ -1326,8 +1327,7 @@ describe('define attrs', () => {
13261327 // @ts -expect-error
13271328 expectType < JSX . Element > ( < MyComp foo = "1" bar = { 1 } /> )
13281329 } )
1329-
1330- test ( 'wrap elements, such as img element (Keep the volar plugin open)' , ( ) => {
1330+ test ( 'wrap elements' , ( ) => {
13311331 const MyImg = defineComponent ( {
13321332 props : {
13331333 foo : String
@@ -1344,13 +1344,14 @@ describe('define attrs', () => {
13441344 expectType < JSX . Element > ( < MyImg class = { 'str' } style = { 'str' } src = { 'str' } /> )
13451345 } )
13461346
1347- test ( 'secondary packaging of components' , ( ) => {
1348- const childProps = {
1349- foo : String
1350- }
1351- type ChildProps = ExtractPropTypes < typeof childProps >
1347+ test ( 'wrap components' , ( ) => {
13521348 const Child = defineComponent ( {
1353- props : childProps ,
1349+ props : {
1350+ foo : String
1351+ } ,
1352+ emits : {
1353+ baz : ( val : number ) => true
1354+ } ,
13541355 render ( ) {
13551356 return < div > { this . foo } </ div >
13561357 }
@@ -1359,13 +1360,25 @@ describe('define attrs', () => {
13591360 props : {
13601361 bar : Number
13611362 } ,
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+ } ,
13631368 render ( ) {
13641369 return < Child { ...this . $attrs } />
13651370 }
13661371 } )
13671372 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+ />
13691382 )
13701383 } )
13711384} )
0 commit comments