Skip to content

Conversation

@kmonahan
Copy link
Collaborator

@kmonahan kmonahan commented Aug 1, 2023

No description provided.

@kmonahan kmonahan requested a review from mdrayer August 1, 2023 21:12
@mdrayer
Copy link
Member

mdrayer commented Aug 2, 2023

Hmm, I think the typing of the options prop/generic could use some help. I was able to use something like

<StyledSelect options={['foo', 'bar']} />

without any type errors in the IDE, but then on the app side:

Unhandled Runtime Error
TypeError: Cannot use 'in' operator to search for 'options' in foo

I think using Option extends DropdownOption instead of Option = DropdownOption in the StyledSelect generics should resolve this. Thoughts?

EDIT: We'd also need this change in the StyledDropdownIndicator generics.

@kmonahan
Copy link
Collaborator Author

kmonahan commented Aug 8, 2023

Diving back into this and going through React Select's types. The docs imply that the Option generic should extend type OptionType = { [string]: any }, but if I do Option extends OptionType = DropdownOption, I do get the type-checker in my IDE preventing me from setting my options to ['foo', 'bar'], but I can do [{ value: 'foo' }, { value: 'bar' }], in which case all the options show up as blank. So I think you're right -- DropdownOption isn't just the default type for StyledSelect, it's also the minimum type. You need value and label for every option, and we should extend DropdownOption.

@kmonahan
Copy link
Collaborator Author

kmonahan commented Aug 8, 2023

Updated! Let's see if this works better

@mdrayer
Copy link
Member

mdrayer commented Aug 24, 2023

Looks good!

@kmonahan kmonahan merged commit 77d8705 into 1.x-RC Aug 29, 2023
@kmonahan kmonahan deleted the fix-styled-select branch August 29, 2023 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants