Skip to content

Generics don't work properly when passing down slot props #1344

Closed
@aradalvand

Description

@aradalvand

Consider the following components:
Form.svelte:

<script lang="ts">
    type TValues = $$Generic;

    export let values: TValues;

    type Errors<T> = {
        [K in keyof T]: string;
    };

    let errors: Errors<TValues>;
</script>

<form>
    <slot {errors} />
</form>

SpecialForm.svelte:

<script lang="ts">
    import Form from './Form.svelte';

    type TValues = $$Generic;

    export let values: TValues;
</script>

<Form
    {values}
    let:errors
>
    <slot {errors} />
</Form>

App.svelte:

<script lang="ts">
    import SpecialForm from './SpecialForm.svelte';

    let values: {
        firstName: string;
        lastName: string;
    };
</script>

<SpecialForm
    {values}
    let:errors
>
    {errors.firstName}
</SpecialForm>

In the last component (App.svelte), the slot prop errors doesn't have the right type, it's of type Errors<unknown> even though the generic type is properly detected for values.
image

I have quite a few components that have this kind of relationship, and generics are not working as expected currently, so I'd appreciate it if you fix this. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglimitationConstraints of the existing architecture make this hard to fixwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions