@@ -10,7 +10,8 @@ import {
1010 SetupContext ,
1111 h ,
1212 SlotsType ,
13- Slots
13+ Slots ,
14+ VNode
1415} from 'vue'
1516import { describe , expectType , IsUnion } from './utils'
1617
@@ -1409,26 +1410,37 @@ export default {
14091410}
14101411
14111412describe ( 'slots' , ( ) => {
1412- defineComponent ( {
1413+ const comp1 = defineComponent ( {
14131414 slots : Object as SlotsType < {
14141415 default : { foo : string ; bar : number }
1415- item : { data : number }
1416+ optional ? : { data : string }
14161417 } > ,
14171418 setup ( props , { slots } ) {
1418- expectType < undefined | ( ( scope : { foo : string ; bar : number } ) => any ) > (
1419+ expectType < ( scope : { foo : string ; bar : number } ) => VNode [ ] > (
14191420 slots . default
14201421 )
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 )
14221433 }
14231434 } )
14241435
1425- defineComponent ( {
1436+ const comp2 = defineComponent ( {
14261437 setup ( props , { slots } ) {
14271438 // unknown slots
14281439 expectType < Slots > ( slots )
1429- expectType < ( ( ...args : any [ ] ) => any ) | undefined > ( slots . default )
1440+ expectType < ( ( ...args : any [ ] ) => VNode [ ] ) | undefined > ( slots . default )
14301441 }
14311442 } )
1443+ expectType < Slots | undefined > ( new comp2 ( ) . $slots )
14321444} )
14331445
14341446import {
0 commit comments