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

[material-ui][Autocomplete] Typescript errors and warnings #38817

Closed
2 tasks done
edx-jagadeesh-kumar opened this issue Sep 5, 2023 · 9 comments
Closed
2 tasks done
Assignees
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material regression A bug, but worse typescript

Comments

@edx-jagadeesh-kumar
Copy link

edx-jagadeesh-kumar commented Sep 5, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

https://codesandbox.io/s/nktnvy?file=/Demo.tsx
Code to reproduce

import * as React from "react";
import TextField from "@mui/material/TextField";
import Autocomplete from "@mui/material/Autocomplete";
interface IFilims {
  label: string;
  year: number;
}
const top100Films: IFilims[] = [
  { label: "The Shawshank Redemption", year: 1994 },
  { label: "The Godfather", year: 1972 },
  { label: "The Godfather: Part II", year: 1974 },
  { label: "The Dark Knight", year: 2008 },
  { label: "12 Angry Men", year: 1957 },

];
export default function ComboBox() {
  const [selectedFilims, setSelectedFilims] = React.useState<IFilims[]>([]);

  return (
    <Autocomplete
      disablePortal
      id="combo-box-demo"
      options={top100Films}
      value={selectedFilims}
      multiple
      sx={{ width: 300 }}
      renderInput={(params) => <TextField {...params} label="Movie" />}
      onChange={(e, v) => setSelectedFilims(v)}
    />
  );
}

// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top

image
image

Current behavior 😯

(parameter) v: readonly IFilims[]
Argument of type 'readonly IFilims[]' is not assignable to parameter of type 'SetStateAction<IFilims[]>'.
  The type 'readonly IFilims[]' is 'readonly' and cannot be assigned to the mutable type 'IFilims[]'.ts(2345)

Throwing warnings and erros in Autocomplete

Expected behavior 🤔

Autocomplete should work fine as before

@edx-jagadeesh-kumar edx-jagadeesh-kumar added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 5, 2023
@edx-jagadeesh-kumar
Copy link
Author

edx-jagadeesh-kumar commented Sep 5, 2023

@brijeshb42 if i use "@mui/material": "5.14.2" it is working fine

@SergioEric
Copy link

SergioEric commented Sep 5, 2023

EDITED!
@brijeshb42
just add a typo in the onChange,

onChange={(_, value) => {
  setState([...value]);
}} 

@kotacode
Copy link

kotacode commented Sep 5, 2023

Same issue. Latest release broke typing for me. Feel like #38253 should have been held for a major release.

@danilo-leal danilo-leal changed the title Typescript Errors and Warning for MUI Autocomplete [material-ui][Autocomplete] Typescript errors and warnings Sep 5, 2023
@danilo-leal danilo-leal added typescript package: material-ui Specific to @mui/material component: autocomplete This is the name of the generic UI component, not the React module! labels Sep 5, 2023
@mnajdova
Copy link
Member

mnajdova commented Sep 6, 2023

Let's revert the pull request. @michaldudak we discussed that we should likely create a copy of the useAutocomplete in Material UI, to allow us to iterate on the one that is currently in Base UI. This is another example of why this may be necessary.

@edx-jagadeesh-kumar
Copy link
Author

Let's revert the pull request. @michaldudak we discussed that we should likely create a copy of the useAutocomplete in Material UI, to allow us to iterate on the one that is currently in Base UI. This is another example of why this may be necessary.

Will this be fixed anytime soon or should i pin my "@mui/material": "5.14.2" version ? Bcz this is working fine .

@brijeshb42
Copy link
Contributor

It's working till 5.14.7. So you can pin that for now. We have a PR in place to revert this.

@stamahto
Copy link

stamahto commented Sep 13, 2023

I have the same issue

@pcorpet
Copy link
Contributor

pcorpet commented Sep 14, 2023

For your initial code, I would recommend updating the useState to

const [selectedFilims, setSelectedFilims] = React.useState<readonly IFilims[]>([]);

@ZeeshanTamboli
Copy link
Member

The reverted PR was released in v5.14.9. Closing this issue.

@ZeeshanTamboli ZeeshanTamboli added bug 🐛 Something doesn't work regression A bug, but worse and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 21, 2023
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! package: material-ui Specific to @mui/material regression A bug, but worse typescript
Projects
None yet
Development

No branches or pull requests

9 participants