enkot / nuxt-open-fetch

Generate zero-overhead, typed OpenAPI clients for Nuxt.
https://nuxt-open-fetch.vercel.app
MIT License
114 stars 10 forks source link

Errors in Custom client fetch client example #48

Closed jonkri closed 1 week ago

jonkri commented 1 week ago

Trying out this code on https://nuxt-open-fetch.vercel.app/advanced/custom-client I encountered two errors:

import type { NitroApp } from "nitropack";
import { createOpenFetch, useRuntimeConfig } from "#imports";

type NitroAppPlugin = (nitro: NitroApp) => void;

// Workaround to add another property to NitroApp
function defineNitroPlugin(def: NitroAppPlugin): NitroAppPlugin {
  return def;
}

export default defineNitroPlugin(({ localFetch }) => {
  const clients = useRuntimeConfig().public.openFetch;

  Object.entries(clients).forEach(([name, options]) => {
    nitroApp[`$${name}`] = createOpenFetch(options, localFetch);
  });
});

Both errors are on this line:

nitroApp[`$${name}`] = createOpenFetch(options, localFetch);

The first error is:

Cannot find name 'nitroApp'.

The second error is:

Argument of type '(input: string | Request, init: FetchOptions) => Promise<Response>' is not assignable to parameter of type '$Fetch<unknown, NitroFetchRequest>'.

Related to #46.

enkot commented 1 week ago

Fixed the docs - https://nuxt-open-fetch.vercel.app/advanced/custom-client.

Thanks :)