Near-future TS changes for possible swr
API changes
#1624
Unanswered
devjmetivier
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
TypeScript is soon to release some changes that would allow for better type inference from destructured discriminated union types: microsoft/TypeScript#46266
It would be great if
swr
could update its public types to include discriminated union types for theSWRResponse
interface with the addition of a property that could leverage these new type inference improvements.Example of possible new
swr
API/usage:The improvements to TS type inference would be that you'd no longer need to check if data is nullish before using it in the above example.
And below would be a contrived example of how the
SWRResponse
type might change with the addition of astatus
property:I imagine that this would reduce the burden of manual type checking for the
data
and/orerror
properties when using those bits of data from the hook. It's also worth noting that at the time of writing this I don't believe these TS improvements have reached any stable release.Let me know what you all think and if I'm missing something :)
Beta Was this translation helpful? Give feedback.
All reactions