Skip to content

[useAutocomplete] Setting the key as shown in the docs, triggers @typescript-eslint/no-unsafe-assignment #47604

Description

@Mario-Eis

Search keywords

no-unsafe-assignment useAutocomplete

Latest version

  • I have tested the latest version

Steps to reproduce

Steps:

  1. Just open the live example with eslint activated: https://codesandbox.io/p/sandbox/fast-dew-mgthpm?from-embed

Current behavior

When doint the workaround for #39833, the eslint rule "@typescript-eslint/no-unsafe-assignment" is triggered because the key is of type "any". Using the "any" type is bad practice. Espacially, when there is a correct type for that usecase available: React.Key

...
const { key, ...optionProps } = getOptionProps({ option, index }); // Unsafe object destructuring of a property with an `any`
return (
    <li key={key} {...optionProps}> // Unsafe assignment of an `any` value.
...

useAutocomplete.d.ts:

  getOptionProps: (renderedOption: UseAutocompleteRenderedOption<Value>) => React.HTMLAttributes<HTMLLIElement> & {
    key: any;
  };

UPDATE: The same is true for the renderOption function Prop

  renderOption?: (props: React.HTMLAttributes<HTMLLIElement> & {
    key: any;
  }, option: Value, state: AutocompleteRenderOptionState, ownerState: AutocompleteOwnerState<Value, Multiple, DisableClearable, FreeSolo, ChipComponent>) => React.ReactNode;

Expected behavior

Keys shold be of type "React.Key" not "any".

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGreat for first contributions. Enable to learn the contribution process.scope: autocompleteChanges related to the autocomplete. This includes ComboBox.type: enhancementIt’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.typescript

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions