-
Notifications
You must be signed in to change notification settings - Fork 407
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
Type errors when using typescript in v6.0.0 #738
Comments
I believe this is a duplicate of #704. You should be able to type the argument of <Typeahead
...
onChange={(selected: StateStat[]) => setSelected(selected)}
/> |
This doesn’t really feel like a very typescript-y solution: you shouldn’t need to re-type the argument. It will make it more painful for typescript users to upgrade to v6. |
Yeah as I alluded, it's a bit of a workaround. There's a bit more detail in the original issue, but truly fixing this problem with generics is pretty involved and has its own tradeoffs. |
Yeah, I understand it’s a work around and I can appreciate that there’s a bit of work to really fix the problem. Is it worth contacting the people who did the DefinitelyTyped definitions? They did a really great job there |
I've taken a look at the DT types and while they did do a nice job, one of the key differences is that they're only declaring types for the public API. To truly type this library in a comprehensive way, I'd also need to propagate types (specifically option generics) throughout the private API, which is significant. I'm definitely open to ideas for how to provide type flexibility without significantly impacting the maintainability of the library. |
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 theAsyncTypeahead
andTypeahead
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’sOption
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:
The text was updated successfully, but these errors were encountered: