@@ -10,7 +10,8 @@ import {
10
10
SetupContext ,
11
11
h ,
12
12
SlotsType ,
13
- Slots
13
+ Slots ,
14
+ VNode
14
15
} from 'vue'
15
16
import { describe , expectType , IsUnion } from './utils'
16
17
@@ -1409,26 +1410,37 @@ export default {
1409
1410
}
1410
1411
1411
1412
describe ( 'slots' , ( ) => {
1412
- defineComponent ( {
1413
+ const comp1 = defineComponent ( {
1413
1414
slots : Object as SlotsType < {
1414
1415
default : { foo : string ; bar : number }
1415
- item : { data : number }
1416
+ optional ? : { data : string }
1416
1417
} > ,
1417
1418
setup ( props , { slots } ) {
1418
- expectType < undefined | ( ( scope : { foo : string ; bar : number } ) => any ) > (
1419
+ expectType < ( scope : { foo : string ; bar : number } ) => VNode [ ] > (
1419
1420
slots . default
1420
1421
)
1421
- expectType < undefined | ( ( scope : { data : number } ) => any ) > ( slots . item )
1422
+ expectType < ( ( scope : { data : string } ) => VNode [ ] ) | undefined > (
1423
+ slots . optional
1424
+ )
1425
+
1426
+ slots . default ( { foo : 'foo' , bar : 1 } )
1427
+
1428
+ // @ts -expect-error it's optional
1429
+ slots . optional ( { data : 'foo' } )
1430
+ slots . optional ?.( { data : 'foo' } )
1431
+
1432
+ expectType < typeof slots | undefined > ( new comp1 ( ) . $slots )
1422
1433
}
1423
1434
} )
1424
1435
1425
- defineComponent ( {
1436
+ const comp2 = defineComponent ( {
1426
1437
setup ( props , { slots } ) {
1427
1438
// unknown slots
1428
1439
expectType < Slots > ( slots )
1429
- expectType < ( ( ...args : any [ ] ) => any ) | undefined > ( slots . default )
1440
+ expectType < ( ( ...args : any [ ] ) => VNode [ ] ) | undefined > ( slots . default )
1430
1441
}
1431
1442
} )
1443
+ expectType < Slots | undefined > ( new comp2 ( ) . $slots )
1432
1444
} )
1433
1445
1434
1446
import {
0 commit comments