react-select-search icon indicating copy to clipboard operation
react-select-search copied to clipboard

TypeScript: wrong declaration for SelectedOptionValue?

Open Vovan-VE opened this issue 4 years ago • 2 comments

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 avatar Jan 15 '21 04:01 Vovan-VE

There are more mistakes:

  • type DomProps has tabIndex: string which is incompatible with React declaration tabIndex?: number: string cannot be assigned to number | undefined;
  • 2nd argument in renderOption is declared as SelectedOption, but SelectSearchOption (options[i]) actually is passing to it.

Vovan-VE avatar Jan 15 '21 05:01 Vovan-VE

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.

manvydasu avatar Jan 24 '21 12:01 manvydasu