rob-balfre / svelte-select

Svelte Select. A select component for Svelte
https://svelte-select-examples.vercel.app
Other
1.25k stars 175 forks source link

Property 'index' does not exist on type '{ selection: any; }' #647

Open StrawHatHacker opened 7 months ago

StrawHatHacker commented 7 months ago

VSCode is warning me that let:index is not typed, but it works as it should. v5.7.0

<Select
    multiple
    {loadOptions}
    bind:value={selected}
    bind:justValue
    on:input={(e) => dispatch('select', e.detail)}
>
    <div
        slot="item"
        let:item
    >
        {item.label}
    </div>
        <div slot="selection" let:selection let:index>
            {selection.label} - {index}
        </div>
    <div slot="empty" >Nothing found...</div>
</Select>
knd775 commented 2 months ago

I think this is a svelte bug/limitation. Index doesn't always exist on that slot, so it doesn't include it in the type. The easy fix would be to just set the index to 0 for non-multiple selects.

@rob-balfre Would you accept a PR that does this?