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

function signature for itemFilter does not include `option` parameter causing typescript error #534

Closed hughlaw closed 1 year ago

hughlaw commented 1 year ago

If you are overriding the itemFilter logic by specifying a custom itemFilter prop on your select, Typescript will complain that the 3rd parameter that does exist in the callback, does not exist.

The type definition for the itemFilter is currently:

itemFilter?: (label: any, filterText: any) => boolean;

but this should be

itemFilter?: (label: any, filterText: any, option: any) => boolean;
rob-balfre commented 1 year ago

It's helpful to pass in the whole option incase people want to filter by a different attribute to the label. I'll investigate how I can bypass the TS error when I'm back from hols. Personally don't code with TS so might need some pointers. Thanks

I'll probably just update the filter to use option[label] by default. That would be non breaking and fix the TS issue I presume?

On Sat, 28 Jan 2023, 2:24 am Hugh Law, @.***> wrote:

If you are overriding the itemFilter logic by specifying a custom itemFilter prop on your select, Typescript will complain that the 3rd parameter that does exist in the callback, does not exist.

The type definition for the itemFilter is currently:

itemFilter?: (label: any, filterText: any) => boolean;

but this should be

itemFilter?: (label: any, filterText: any, option: any) => boolean;

— Reply to this email directly, view it on GitHub https://github.com/rob-balfre/svelte-select/issues/534, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUAM7R2SAGCCGIK7V6PMZ3WUPEANANCNFSM6AAAAAAUIWHJ7A . You are receiving this because you are subscribed to this thread.Message ID: @.***>

hughlaw commented 1 year ago

Yeah, that's pretty much how I discovered it - I'm passing in an object for each option and filtering based in multiple properties. Everything works, just typescript complains about it 😆

I forked the project and was going to submit a PR but couldn't figure out how the types are generated... is there a build process that create the types as part of the npm package? Happy to take a look if you can point me in the right direction.

rob-balfre commented 1 year ago

It's automatically done by the kit package process. If you update the default filter to always use option it should fix the issue. Away from comp though so cant help

On Sat, 28 Jan 2023, 10:53 am Hugh Law, @.***> wrote:

Yeah, that's pretty much how I discovered it - I'm passing in an object for each option and filtering based in multiple properties. Everything works, just typescript complains about it 😆

I forked the project and was going to submit a PR but couldn't figure out how the types are generated... is there a build process that create the types as part of the nom package? Happy to take a look if you can point me in the right direction.

— Reply to this email directly, view it on GitHub https://github.com/rob-balfre/svelte-select/issues/534#issuecomment-1407113740, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUAM7VE26HYIDEM4RXFB6LWUQ7VZANCNFSM6AAAAAAUIWHJ7A . You are receiving this because you commented.Message ID: @.***>

rob-balfre commented 1 year ago

Should be fixed in 5.1.4

Thanks @hughlaw