Strict type Children in Slots #733
Replies: 2 comments 2 replies
-
Shouldn't it be
? |
Beta Was this translation helpful? Give feedback.
-
That would be beneficial, though, a bit off Vue philosophy where a component doesn't know its slot content. If Vue had something like this, I think it should also support more complex scenarios. 1 - Fragments. In this case Tabs's <Tabs>
<template v-if="catsAreTheBest">
<TabItem id="small-cat" />
<TabItem id="big-cat" />
</template>
<TabItem v-else id="dog" />
</Tabs> 2 - Wrapper components. A developer may want to create a wrapper component for a specific child or a list of children to reuse it between components. <Tabs>
<TabItem id="small-cat" />
<TabItem id="big-cat" />
<TabItem id="dog" />
<TabItem id="ferret" />
</Tabs>
<!-- replaced with -->
<Tabs>
<CatsTabItems /> <!-- Renders small-cat and big-cat tabs -->
<TabItem id="dog" />
<MyFerretTabItem /> <!-- Renders the ferret tab -->
</Tabs> |
Beta Was this translation helpful? Give feedback.
-
Summary
Allow for tools to enforce strict children type for Slots, by allowing to describe what type of children can be used in the slot.
Basic example
Tab.vue
Comp.vue
Motivation
Allow greater control for library creators to specify what can be used for children.
Detailed design
This is the bulk of the RFC. Explain the design in enough detail for somebody
familiar with Vue to understand, and for somebody familiar with the
implementation to implement. This should get into specifics and corner-cases,
and include examples of how the feature is used. Any new terminology should be
defined here.
This only affects Typescript declaration,
SlotComponent
can be renamed to something else,without a specific type to allow granualy defining the required props and the Component, it will become quite difficult to extract it in Typescript while maintainnig the correct type.
Returns
Strict numered of children:
Type:
Drawbacks
The main draw back is this is to be mostly use by tooling, vue language tools and others can get this information and provide better DX.
Alternatives
This does not need a Vue core change, since
defineSlots
does not strict check the types, this is to be mostly adopted by tools.Adoption strategy
Can be adopted as soon as there's support for Vue language tools.
Unresolved questions
SlotComponent
naming?Beta Was this translation helpful? Give feedback.
All reactions