Skip to content
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

fix: type event.$fetch and event.fetch #1343

Merged
merged 11 commits into from
Jun 28, 2023
Prev Previous commit
Next Next commit
fix types for event.fetch
  • Loading branch information
pi0 committed Jun 28, 2023
commit bdda171c247c3c67595cbf512f474b24d966374b
13 changes: 4 additions & 9 deletions src/runtime/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,11 @@ function createNitroApp(): NitroApp {
}
// Assign bound fetch to context
event.fetch = (req, init) =>
fetchWithEvent<Promise<Response>, NitroFetchRequest>(
event,
req as any,
init,
{
fetch: localFetch,
}
);
fetchWithEvent<Promise<Response>, NitroFetchRequest>(event, req, init, {
fetch: localFetch,
});
event.$fetch = ((req, init) =>
fetchWithEvent(event, req as any, init as RequestInit, {
fetchWithEvent(event, req, init as RequestInit, {
fetch: $fetch,
})) as $Fetch<unknown, NitroFetchRequest>;
})
Expand Down
7 changes: 5 additions & 2 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { H3Event } from "h3";
import type { H3Event, fetchWithEvent } from "h3";

import type { $Fetch, NitroFetchRequest } from "../types";
import type { RenderResponse } from "./types";
Expand All @@ -15,7 +15,10 @@ export type { RenderResponse, RenderHandler } from "./renderer";
declare module "h3" {
interface H3Event {
/** @experimental Calls fetch with same context and request headers */
fetch: typeof globalThis.fetch;
fetch: (
request: NitroFetchRequest,
init?: RequestInit
) => Promise<Response>;
/** @experimental Calls fetch with same context and request headers */
$fetch: $Fetch<unknown, NitroFetchRequest>;
}
Expand Down
Loading