@@ -12,7 +12,9 @@ import {
1212 SlotsType ,
1313 AttrsType ,
1414 Slots ,
15- VNode
15+ VNode ,
16+ ImgHTMLAttributes ,
17+ StyleValue
1618} from 'vue'
1719import { describe , expectType , IsUnion , test } from './utils'
1820
@@ -1325,22 +1327,45 @@ describe('define attrs', () => {
13251327 expectType < JSX . Element > ( < MyComp foo = "1" bar = { 1 } /> )
13261328 } )
13271329
1328- test ( 'default attrs like class, style ' , ( ) => {
1329- const MyComp = defineComponent ( {
1330+ test ( 'wrap elements, such as img element (Keep the volar plugin open) ' , ( ) => {
1331+ const MyImg = defineComponent ( {
13301332 props : {
13311333 foo : String
13321334 } ,
1333- attrs : Object as AttrsType < {
1334- bar ?: number
1335- } > ,
1335+ attrs : Object as AttrsType < ImgHTMLAttributes > ,
13361336 created ( ) {
1337- expectType < number | undefined > ( this . $attrs . bar )
1338- expectType < unknown > ( this . $attrs . class )
1339- expectType < unknown > ( this . $attrs . style )
1337+ expectType < any > ( this . $attrs . class )
1338+ expectType < StyleValue | undefined > ( this . $attrs . style )
1339+ } ,
1340+ render ( ) {
1341+ return < img { ...this . $attrs } />
1342+ }
1343+ } )
1344+ expectType < JSX . Element > ( < MyImg class = { 'str' } style = { 'str' } src = { 'str' } /> )
1345+ } )
1346+
1347+ test ( 'secondary packaging of components' , ( ) => {
1348+ const childProps = {
1349+ foo : String
1350+ }
1351+ type ChildProps = ExtractPropTypes < typeof childProps >
1352+ const Child = defineComponent ( {
1353+ props : childProps ,
1354+ render ( ) {
1355+ return < div > { this . foo } </ div >
1356+ }
1357+ } )
1358+ const Comp = defineComponent ( {
1359+ props : {
1360+ bar : Number
1361+ } ,
1362+ attrs : Object as AttrsType < ChildProps > ,
1363+ render ( ) {
1364+ return < Child { ...this . $attrs } />
13401365 }
13411366 } )
13421367 expectType < JSX . Element > (
1343- < MyComp class = { 'str' } style = { 'str' } foo = "1" bar = { 1 } />
1368+ < Comp class = { 'str' } style = { 'str' } bar = { 1 } foo = { 'str' } />
13441369 )
13451370 } )
13461371} )
0 commit comments