question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type errors when using typescript in v6.0.0

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bggoldingcommented, Oct 6, 2022

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.

0reactions
ericgiocommented, Oct 11, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript error TS2339: Property 'matches' does not exist on ...
I'm using version 4.1.2 of TypeScript and v6.0.0-alpha.1 of Gulp Typescript. It's obviously a configuration issue somewhere, but I don't know ...
Read more >
Node.js v19.3.0 Documentation
Iterates through the list of functions passed to tracker.calls() and will throw an error for functions that have not been called the expected...
Read more >
Troubleshooting .NET Framework Targeting Errors - MSBuild
To resolve the error, make sure that your application targets a .NET version that's compatible with the version that's targeted by the projects ......
Read more >
Home - Contentful Developer Documentation
Unlike a CMS, Contentful was built to integrate with the modern software stack. ... October 2017); Supports Environments (since v6.0.0 - 06. April...
Read more >
Changelog | Pact Docs
dsl/verifier - express import typescript error (60fa69f) ... broken pact provider test not consistent with types (29af342) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found