tbleckert / react-select-search

⚡️ Lightweight select component for React
https://react-select-search.com
MIT License
676 stars 149 forks source link

TypeScript: wrong declaration for SelectedOptionValue? #158

Open Vovan-VE opened 3 years ago

Vovan-VE commented 3 years ago

Hello.

Version 2.2.4. From TypeScript declaration:

export type SelectedOptionValue = {
    name:string
    value:string
    index:number
    photo?:string
    disabled?:boolean
}

export type SelectedOption = {
    defaultOptions:SelectedOptionValue[][]
    focus:boolean
    highlighted:null|SelectedOptionValue
    options:SelectedOptionValue[][]
    search:string
    value:string
}

// ...

export type SelectSearchProps = {
    // ...
    value?:string|string[]
    // ...
    onChange?:(
        selectedValue:SelectedOptionValue|SelectedOptionValue[],
        selectedOption:SelectedOption|SelectedOption[],
        optionSnapshot:SelectSearchProps
    ) => void
    // ...
}

However onChange actually receives (string, SelectedOption) and not (SelectedOptionValue, SelectedOption) (multiple=false).

Either SelectedOptionValue declared wrong or onChange 1st argument must be string|string[] (same as type of value).

Vovan-VE commented 3 years ago

There are more mistakes:

manvydasu commented 3 years ago

The library is quite small. Perhaps it should be rewritten in typescript? It would be easier to avoid such mistakes then and it shouldn't be that hard.