Skip to content

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

@edx-jagadeesh-kumar

Description

@edx-jagadeesh-kumar

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

Metadata

Metadata

Assignees

Labels

scope: autocompleteChanges related to the autocomplete. This includes ComboBox.type: regressionA bug, but worse, it used to behave as expected.typescript

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions