Skip to content

Commit

Permalink
Use global Request type for all request instances
Browse files Browse the repository at this point in the history
this resolves a type error that was being triggered when using handleFetch<env>(request, …) from a worker.ts script (e.g. in examples/remix-cms). the full TS error:

worker.ts:17:37 - error TS2345: Argument of type 'Request<unknown, IncomingRequestCfProperties<unknown>>' is not assignable to parameter of type 'import("/Users/andrew/Projects/superflare/node_modules/.pnpm/@cloudflare[email protected]/node_modules/@cloudflare/workers-types/index").Request<unknown, import("/Users/andrew/Projects/superflare/node_modules/.pnpm/@cloudflare[email protected]/node_modules/@cloudflare/workers-types/index").Incomi...'.
  The types of 'clone().headers' are incompatible between these types.
    Property 'getAll' is missing in type 'Headers' but required in type 'import("/Users/andrew/Projects/superflare/node_modules/.pnpm/@cloudflare[email protected]/node_modules/@cloudflare/workers-types/index").Headers'.

17       return await handleFetch<Env>(request, env, ctx, config, handleRequest);
  • Loading branch information
acusti committed Nov 19, 2024
1 parent 6c4a22b commit 1f267c7
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 19 deletions.
8 changes: 1 addition & 7 deletions packages/superflare-remix/dev.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
type IncomingRequestCfProperties,
type Request,
} from "@cloudflare/workers-types";
import { cloudflareDevProxyVitePlugin } from "@remix-run/dev";
import {
fromNodeRequest,
Expand All @@ -15,8 +11,6 @@ import { type Plugin, type ViteDevServer } from "vite";
import { type GetPlatformProxyOptions } from "wrangler";
import { type Cloudflare, getLoadContext } from "./load-context";

type WorkersRequest = Request<unknown, IncomingRequestCfProperties<unknown>>;

/**
* This is copied from the workers-sdk repo (used for wrangler’s getPlatformProxy).
* Using `waitUntil` means invoking the async function, so a no-op works in dev.
Expand Down Expand Up @@ -76,7 +70,7 @@ export function superflareDevProxyVitePlugin<Env extends { APP_KEY: string }>(
const request = fromNodeRequest(nodeReq, nodeRes);
const loadContext = await getLoadContext<Env>({
context,
request: request as unknown as WorkersRequest,
request,
SuperflareAuth: superflare.SuperflareAuth,
SuperflareSession: superflare.SuperflareSession,
});
Expand Down
6 changes: 1 addition & 5 deletions packages/superflare-remix/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
type IncomingRequestCfProperties,
type Request as WorkersRequest,
} from "@cloudflare/workers-types";
import { type AppLoadContext } from "@remix-run/cloudflare";
import {
type DefineConfigReturn,
Expand All @@ -27,7 +23,7 @@ declare module "@remix-run/cloudflare" {
* It calls getLoadContext to inject `auth` and `session` into the Remix load context.
*/
export async function handleFetch<Env extends { APP_KEY: string }>(
request: WorkersRequest<unknown, IncomingRequestCfProperties<unknown>>,
request: Request,
env: Env,
ctx: ExecutionContext,
config: DefineConfigReturn<any>,
Expand Down
1 change: 0 additions & 1 deletion packages/superflare-remix/load-context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type Request } from "@cloudflare/workers-types";
import {
type AppLoadContext,
createCookieSessionStorage,
Expand Down
1 change: 0 additions & 1 deletion packages/superflare/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type Request } from "@cloudflare/workers-types";
import { sanitizeModuleName } from "./string";

export interface StorageDiskConfig {
Expand Down
6 changes: 1 addition & 5 deletions packages/superflare/src/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
type IncomingRequestCfProperties,
type Request,
} from "@cloudflare/workers-types";
import { type DefineConfigReturn } from "./config";
import { type SuperflareSession } from "./session";

Expand All @@ -14,7 +10,7 @@ export async function handleFetch<Env>(
session,
getSessionCookie,
}: {
request: Request<unknown, IncomingRequestCfProperties<unknown>>;
request: Request;
env: Env;
ctx: ExecutionContext;
config: DefineConfigReturn<Env>;
Expand Down

0 comments on commit 1f267c7

Please sign in to comment.