react-select-search
react-select-search copied to clipboard
TypeScript: wrong declaration for SelectedOptionValue?
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).
There are more mistakes:
type DomPropshastabIndex: stringwhich is incompatible with React declarationtabIndex?: number:stringcannot be assigned tonumber | undefined;- 2nd argument in
renderOptionis declared asSelectedOption, butSelectSearchOption(options[i]) actually is passing to it.
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.