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 inferred value type when multiple prop is true #35275

Merged
merged 2 commits into from Nov 28, 2022

Conversation

fenghan34
Copy link
Contributor

Fixes: #35099

@mui-bot
Copy link

mui-bot commented Nov 27, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-35275--material-ui.netlify.app/

No bundle size changes

Generated by 🚫 dangerJS against 8b92c94

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

Thanks. Please add a TypeScript test case in Autocomplete.spec.tsx.

@ZeeshanTamboli ZeeshanTamboli added bug 🐛 Something doesn't work typescript component: autocomplete This is the name of the generic UI component, not the React module! PR: needs test The pull request can't be merged labels Nov 28, 2022
@fenghan34
Copy link
Contributor Author

Added, please let me know if need any changes.

@ZeeshanTamboli ZeeshanTamboli removed the PR: needs test The pull request can't be merged label Nov 28, 2022
@ZeeshanTamboli ZeeshanTamboli changed the title [Autocomplete] Fix inferred value type when use multiple prop with true [Autocomplete] Fix inferred value type when multiple prop is true Nov 28, 2022
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

It's a great first pull request on Material UI 👌 Thank you for working on it!

@ZeeshanTamboli ZeeshanTamboli merged commit 86a3404 into mui:master Nov 28, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
@LeoniakM
Copy link

LeoniakM commented Nov 30, 2022

I have to set multiple explicitly to false otherwise I get TS2322: Type 'string' is not assignable to type 'string[]'.

Am I doing something wrong?

Should i create a Issue for that?

@hortizgarrido
Copy link

I see that too. I get Type string is not assignable to string[]. For some reason i have to now include the type in my autocomplete as follows so that it works:

<Autocomple ....

@fenghan34
Copy link
Contributor Author

Hi @LeoniakM, would you mind providing the code example so I can debug it?

@sucy6330133
Copy link

Same issue here, complaint that number / string is not assigned to (number | string)[]. I can walk-around this by adding multiple={false}.

@LeoniakM
Copy link

LeoniakM commented Dec 5, 2022

export const BuggyAutocomplete: VoidFunctionComponent = () => {
  const [options, setOptions] = useState<string[]>(['asd', 'fgh'])
  return (
    <Autocomplete options={options} renderInput={() => <TextField />} value={options[0]} />
  )
}

gives me "TS2322: Type 'string' is not assignable to type 'string[]'."

@fenghan34
Copy link
Contributor Author

Hi @LeoniakM, thank you for the code example. I just tested it locally and on StackBlitz, but I haven't found any issue. Seems like we are in different environments, so can you provide the environment of your codebase by executing npx @mui/envinfo?

@LeoniakM
Copy link

LeoniakM commented Dec 5, 2022

Hi @LeoniakM, thank you for the code example. I just tested it locally and on StackBlitz, but I haven't found any issue. Seems like we are in different environments, so can you provide the environment of your codebase by executing npx @mui/envinfo?

  System:                                                    
    OS: Windows 10 10.0.19044
  Binaries:
    Node: 16.13.1 - C:\Software\Node16\node.EXE
    Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.19.2 - C:\Software\Node16\npm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Spartan (44.19041.1266.0), Chromium (107.0.1418.62)
  npmPackages:
    @emotion/react: ^11.8.2 => 11.10.0 
    @emotion/styled: ^11.8.1 => 11.10.0 
    @mui/base:  5.0.0-alpha.93 
    @mui/core-downloads-tracker:  5.10.16 
    @mui/icons-material: ^5.5.1 => 5.8.4 
    @mui/lab: ^5.0.0-alpha.90 => 5.0.0-alpha.95 
    @mui/material: 5.10.16 => 5.10.16 
    @mui/private-theming:  5.10.16 
    @mui/styled-engine:  5.10.16 
    @mui/system:  5.10.16 
    @mui/types:  7.2.2 
    @mui/utils:  5.10.16 
    @mui/x-data-grid: ^5.12.0 => 5.15.3 
    @mui/x-date-pickers: ^5.0.0-beta.0 => 5.0.0-beta.6       
    @types/react: 17.0.1 => 17.0.1 
    react: ^17.0.2 => 17.0.2 
    react-dom: ^17.0.2 => 17.0.2
    styled-components: ^5.3.5 => 5.3.5
    typescript: 4.9.3 => 4.9.3

Edit: I updated Node to 18, but the issue still appears.

@gnowland
Copy link
Contributor

gnowland commented Dec 5, 2022

Example added to issue #35308

feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work 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.

[Autocomplete] types break when having multiple default values
7 participants