nuxt-open-fetch
nuxt-open-fetch copied to clipboard
Expose FetchOptions type helper
Describe the feature
Referencing fetch.ts, it would be great to have an FetchOptions type helper.
Assuming a foo client is defined in nuxt.config.ts, here is a proposed API:
import type { FooFetchOptions } from "#open-fetch";
type Options = FooFetchOptions<"/some/api/path">;
My use case involves creating a <Form> component that consumes the client parameters and performs some runtime error checking along with some other tasks:
<Form
path="/some/api/path"
:options="{ method: "post", body: { bar: "something-else" } }"
>
...
</Form>
The <Form> implementation would ideally accept a generic type to perform the checking:
<script setup lang="ts" generic="Path">
import type { FooFetchOptions } from "#open-fetch";
defineProps<{
path: Path;
options: FooFetchOptions<Path>;
}>();
</script>
This way, the path and options params are checked against each other to ensure they are a valid combination.
I've attempted to write the type for this to no avail. Some things I've tried:
Parameters<OpenFetchClient<Paths>>[1]- Basically rewriting
OpenFetchClient<Paths>
I'm not really sure where to proceed here, but this would be really helpful for my team.
Additional information
- [x] Would you be willing to help implement this feature?
Final checks
- [x] Read the contribution guide.
- [x] Check existing discussions and issues.
The way the options are currently typed makes it a bit tricky to extract or expose them in this way. I worked on my first PR here yesterday and had some ideas of how that could be improved. No promises yet if anything will come out of it