@@ -12,7 +12,9 @@ import {
12
12
SlotsType ,
13
13
AttrsType ,
14
14
Slots ,
15
- VNode
15
+ VNode ,
16
+ ImgHTMLAttributes ,
17
+ StyleValue
16
18
} from 'vue'
17
19
import { describe , expectType , IsUnion , test } from './utils'
18
20
@@ -1325,22 +1327,45 @@ describe('define attrs', () => {
1325
1327
expectType < JSX . Element > ( < MyComp foo = "1" bar = { 1 } /> )
1326
1328
} )
1327
1329
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 ( {
1330
1332
props : {
1331
1333
foo : String
1332
1334
} ,
1333
- attrs : Object as AttrsType < {
1334
- bar ?: number
1335
- } > ,
1335
+ attrs : Object as AttrsType < ImgHTMLAttributes > ,
1336
1336
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 } />
1340
1365
}
1341
1366
} )
1342
1367
expectType < JSX . Element > (
1343
- < MyComp class = { 'str' } style = { 'str' } foo = "1" bar = { 1 } />
1368
+ < Comp class = { 'str' } style = { 'str' } bar = { 1 } foo = { 'str' } />
1344
1369
)
1345
1370
} )
1346
1371
} )
0 commit comments