Open ysemennikov opened 1 month ago
+1 This would be really nice
The typing issue doesn't seem to appear if you use the library like this:
export function createLibrary(data: CreateLibraryRequest) {
return apiFetch<Library>(route('api.library.create'), {
method: 'POST',
body: data,
})
}
I ran into the same issue like you, but if i adjust my request all seems to be good.
The typing issue doesn't seem to appear if you use the library like this:
export function createLibrary(data: CreateLibraryRequest) { return apiFetch<Library>(route('api.library.create'), { method: 'POST', body: data, }) }
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:
const apiFetch = ofetch.create<apiTypes>()
.
And then all requests will be already properly typed.
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