nuxt-open-fetch icon indicating copy to clipboard operation
nuxt-open-fetch copied to clipboard

Expose FetchOptions type helper

Open marcus-mclean-miris opened this issue 2 months ago • 1 comments

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:

  1. Parameters<OpenFetchClient<Paths>>[1]
  2. 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

marcus-mclean-miris avatar Oct 07 '25 03:10 marcus-mclean-miris

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

Jak-Ch-ll avatar Oct 11 '25 09:10 Jak-Ch-ll