-
Notifications
You must be signed in to change notification settings - Fork 129
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
Add support of TS type annotations on ofetch.create
#406
Comments
+1 This would be really nice |
The typing issue doesn't seem to appear if you use the library like this:
I ran into the same issue like you, but if i adjust my request all seems to be good. |
You are right, but in this case you need to manually define a return type for each request you send. I suggest another feature - creating an ofetch instance and passing a generic type like this: And then all requests will be already properly typed. |
Is there currently any workaround to this? I'm using Nuxt API Party which gives me a fetch client (based on openapi-typescript). I'm passing an openapi schema so I'm getting type-safety for paths, queries, etc. I need custom interceptors logic so I tried passing the generated fetch client to // $typedFetch is the fetch client generated by API Party module
const customFetch = createFetch({ fetch: $typedFetch }).create({
baseURL: 'my-api-url',
onRequest({ options }) {
// Custom options
},
})
// This doesn't provide intellisense
await customFetch('endpoint-path')
// This does provide intelliSense, but can't extend it
await $typedFetch('endpoint-path') |
Describe the feature
Hi everyone!
I really love using ofetch because it's very powerful and covers almost all use cases.
The one feature that is missing for me is type annotatations. I believe this could be automated using tools like openapi-typescript, which can generate TS-types based on OpenAPI specification.
So what I mean is:
The
openapi-typescript
has its own package calledopenapi-fetch
with support of this feature, but sinceofetch
is great integrated into Nuxt 3, it would be very nice to also have this possibility here. Andofetch
has more features than theopenapi-fetch
.Additional information
The text was updated successfully, but these errors were encountered: