Subscribe on changes!

Feature: Vue 3, defineComponent: Allow to define slots inside defineComponent function

avatar
Feb 3rd 2022

What problem does this feature solve?

I am trying to create generic component.

I managed to create component with generic props using this tutorial: https://logaretm.com/blog/generically-typed-vue-components/

However, it does not help to create generic slots because "script" section contains no information about slots.

Adding slots definitions to defineComponent would allow to use technique described here: https://logaretm.com/blog/generically-typed-vue-components/ to create generic slots.

What does the proposed API look like?

defineComponent({
  slots: {
    slot1: {
      name: "slot-name",
      data: SlotDataType<{ a: string, b: number }>
    }
  }
})

Then tools like Valor could extract slot data types from DefineComponent.

avatar
Feb 3rd 2022

Volar already extracts the slot typing. Duplicate of https://github.com/vuejs/core/issues/3102 (Generic components)