Skip to content

Add better support for generic types when exporting component as library #16393

@LexRiver

Description

@LexRiver

Describe the problem

I'm trying to export component as library

<script lang="ts" generics="ItemType">
    const props: Props<ItemType> = $props();
...

But when I try to import this component, the type ItemType becomes unknown

The only workaround I found is this:

<script lang="ts">
    const TypedMyComponent = MyComponent<string>;
    const items = ['a','b']
</script>

<TypedMyComponent items={items} />

It look unfriendly in my opinion, is there any better option?
Why svelte cannot infer type the same way as if component is in the same project?

Why there is nothing about exporting with generic types in the docs?

Describe the proposed solution

It would be great to use the imported component with generics the same way as the local component:

<MyComponent items={items} />

Importance

would make my life easier

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