Skip to content

MUI Autocomplete onChange: Wrong value type #2392

@hofi99

Description

@hofi99

I noticed that since [this] (#2288) PR, the Autocomplete onChange value parameter is Any.
But actually it should be Any? because clearing the Autocomplete can return null.
This leads to a runtime exception after clearing the Autocomplete component when in the onChange value is specified as Any.

E.g. of failing example

Autocomplete<AutocompleteProps<String>> {
  value = state.value
  onChange = { _, value: Any, _, _ -> // This causes the runtime exception.
    value as String
    setState {
      this.value = value
    }
  }
 // etc.
}

E.g. of working example

Autocomplete<AutocompleteProps<String>> {
  value = state.value
  onChange = { _, value: Any?, _, _ ->
    value as String?
    setState {
      this.value = value
    }
  }
 // etc.
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions