Next.js plugin for automatic API types using SWR and TypeScript #32855
Unanswered
mohsen1
asked this question in
Show and tell
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.
Uh oh!
There was an error while loading. Please reload this page.
-
next-typed-api-with-swr
I just published next-typed-api-with-swr Next.js plugin that makes calls to
useSWR
strongly typed based on types of API handlers inpages/api
directory.It works by generating a TypeScript file that contributes more overloads to
useSWR
function types. Those overloads are looking for the API path you're using. For instance calls to"/api/users"
are strongly typed based on the types of API handler inpages/api/users.ts
file.To-do and ideas
I want to make it work for more use cases. As of now I have the following ideas
useSWR("/api/users/123")
is also strongly typeduseSWR
Looking for feedback
If you are using
useSWR
and TypeScript in yoru Next.js project, please give this plugin a shot and let me know what works and what doesn't work for you.Beta Was this translation helpful? Give feedback.
All reactions