Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Autocomplete] Fix useAutocomplete groupedOptions type #23854

Merged

Conversation

ZachCMP
Copy link
Contributor

@ZachCMP ZachCMP commented Dec 5, 2020

Question about this:

I had to update the demos to fix type errors caused by the type definition change. The current demos aren't explicit about the fact that groupedOptions changes shape when groupBy is provided; And their behavior will actually break without explanation if you do provide groupBy to useAutocomplete (Demo). With the type definition change, you do get type errors now if you don't handle the union type on groupedOptions, which is good, but I think it would be of benefit to add a bit more explanation of that behavior to the demos, as it seems a bit unexpected to me. I'm happy to do that, I'm just wondering what form you think would be appropriate. Would just a comment do? Would you want an example of how to actually handle the different types? Or something else? What do you think?

Fixes #23846

@mui-pr-bot
Copy link

mui-pr-bot commented Dec 5, 2020

No bundle size changes

Generated by 🚫 dangerJS against 57b5065

@ZachCMP ZachCMP changed the title Fix useAutocomplete groupedOptions type [ useAutocomplete ] Fix useAutocomplete groupedOptions type Dec 5, 2020
@oliviertassinari oliviertassinari changed the title [ useAutocomplete ] Fix useAutocomplete groupedOptions type [Autocomplete] Fix useAutocomplete groupedOptions type Dec 5, 2020
@oliviertassinari oliviertassinari added component: autocomplete This is the name of the generic UI component, not the React module! typescript labels Dec 5, 2020
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this comment?

@ZachCMP
Copy link
Contributor Author

ZachCMP commented Dec 6, 2020

@oliviertassinari Yeah, that would work. Can we be explicit that "if the grouping feature is enabled" means that the groupBy prop is defined? Otherwise I'm not sure it's clear exactly when "the grouping feature is enabled". So something like:

The options to render. It's either `T[]` or `AutocompleteGroupedOption<T>[]` if the groupBy prop is provided.

@oliviertassinari
Copy link
Member

@ZachCMP Sure, it sounds good.

@ZachCMP
Copy link
Contributor Author

ZachCMP commented Dec 6, 2020

@oliviertassinari Comment updated. I'm happy with it now. Let me know if there's anything else you'd like me to add to this PR

@oliviertassinari oliviertassinari merged commit 3246681 into mui:next Dec 6, 2020
@oliviertassinari
Copy link
Member

@ZachCMP Thanks for the polish

@HJain13
Copy link

HJain13 commented Dec 7, 2020

Also came across this problem today. waiting for the new build with this merged in 🙏

@oliviertassinari
Copy link
Member

@HJain13 We will likely release this weekend. In the meantime, you could potentially use https://github.com/mui-org/material-ui/blob/next/CONTRIBUTING.md#how-can-i-use-a-change-that-wasnt-released-yet.

@ZachCMP ZachCMP deleted the issues/23846-useautocomplete-type-fix branch December 8, 2020 13:53
@jackHedaya
Copy link

Is this included in the most recent version? I'm experiencing this issue on 4.0.0-alpha.57

@oliviertassinari
Copy link
Member

@jackHedaya The most recent version is v5.0.0-alpha.21.

@spencermehta
Copy link

Shouldn't the type here actually be conditional upon the type of the groupBy prop? If it is not provided the type should be T[] and if it is provided it should be Array<AutocompleteGroupedOption<T>>. With the current implementation I'm forced to handle the case that the options are of type T[] even if I've provided the groupBy prop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[useAutocomplete] groupedOptions type definition seems wrong
6 participants