diff --git a/src/guide/typescript/composition-api.md b/src/guide/typescript/composition-api.md index 26fc38e2b5..ca941427d9 100644 --- a/src/guide/typescript/composition-api.md +++ b/src/guide/typescript/composition-api.md @@ -218,6 +218,51 @@ export default defineComponent({ }) ``` +## Typing Component Slots {#typing-component-slots} + +In ` + + +``` + +While Vue can infer slot types from `` usage in the template, `defineSlots()` allows you to declare an explicit contract so parent components have better type checking and auto-completion for slot names and slot props. See [defineSlots()](/api/sfc-script-setup#defineslots) for more details. + +### Forwarding Slots in Recursive Components {#forwarding-slots-in-recursive-components} + +A component can forward all of a slot's props to a child component's slot with ``. When that child is the component itself, also known as a [recursive component](/api/sfc-script-setup#recursive-components), TypeScript can't infer the type of `slotProps` and reports `'slotProps' implicitly has type 'any'` unless the slot type is declared explicitly with `defineSlots()`: + + + + +``` + + ## Typing `ref()` {#typing-ref} Refs infer the type from the initial value: