How to represent a generic return type of a fetch handler #1684
Unanswered
mckernanin
asked this question in
Q&A
Replies: 1 comment
-
One more note, I can use the existing function to cache the response, but it would end up caching an error as well (and without specifying a type for |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Working on converting a project form using an old generated swagger client, I have a caching function that looks like this:
get/setJSON are just wrappers around redis,
Implementation looks like this, and it properly passes the response type through:
I'm trying to implement something similar for caching responses for calls made with openapi-fetch, but am struggling to type the function properly. Currently, I have this:
Implemented the same way, but with openapi-fetch, the type doesn't narrow down to the actual return type of the request, resulting in
unknown
being the type ofcachedOrFetched
when using the second version of the function. Is there a type exported that I can use to represent any (haha) return value from open-api fetch, without requiring any generics to be passed in?Beta Was this translation helpful? Give feedback.
All reactions