Skip to content

Type errors when using typescript in v6.0.0 #738

Closed
@bggolding

Description

@bggolding

Version

6.0.0

Description

When I updated my typescript project to use v6.0.0, there are errors appearing because the generic type of the Option that the AsyncTypeahead and Typeahead components use has been removed. When I remove the generic argument in my code, I get errors in my code because the types of Typeahead’s Option type don’t match my object.

I think the use of the generic type on AsyncTypeahead and Typeahead that was in the DefinitelyTyped types for the v5 version was exactly the right way to do this and it would be great if that was reinstated. This would also ease the upgrade path for typescript projects.

I have put together a codesandbox example that shows the error:

https://codesandbox.io/s/pensive-antonelli-o84wbj?file=/src/index.tsx

In my project, I’m getting errors on the labelKey prop as well. I’m not sure why that’s not showing in my example.

Expected Behavior

It shouldn’t be necessary to bypass the typing system on the onChange prop to get the code to build cleanly.

Actual Behavior

I get this error:

Type 'Dispatch<SetStateAction<StateStat[]>>' is not assignable to type '(selected: Option[]) => void'.
  Types of parameters 'value' and 'selected' are incompatible.
    Type 'Option[]' is not assignable to type 'SetStateAction<StateStat[]>'.
      Type 'Option[]' is not assignable to type 'StateStat[]'.
        Type 'Option' is not assignable to type 'StateStat'.
          Type 'string' is not assignable to type 'StateStat'.ts(2322)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions