Skip to content

ComponentSlots<> doesn't work with generic components (FunctionalComponent in general?) #3764

@pinguet62

Description

@pinguet62

Hello 🖖

Sample

<template>
  <div>
    <slot name="child" />
  </div>
</template>

<script lang="ts" setup generic="T">
</script>

ComponentSlots<typeof Sample> always return {}.

Generics

For generic components (<script setup lang="ts" generic="...">) Vue processor generate a FunctionalComponent.
And ComponentSlots<typeof MyGenericComponent> always returns {}.

Fix

The original implementation of ComponentSlots is

export type ComponentSlots<T> =
	T extends new () => { $slots: infer S; } ? NonNullable<S> :
	T extends (props: any, ctx: { slots: infer S; }, ...args: any) => any ? NonNullable<S> :
	{};

If I change by adding attrs & emit fields in context:

export type ComponentSlots<T> =
	T extends new () => { $slots: infer S } ? NonNullable<S> :
	T extends (props: any, ctx: { slots: infer S; attrs: any; emit: any }, ...args: any) => any ? NonNullable<S> :
	{}

it works

ComponentEmit

Probably same error with ComponentEmit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions