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

ExecutionContext type mismatch in @cloudflare/workers-types and PlatformProxy #3290

Open
shmuli9 opened this issue Jan 6, 2025 · 0 comments
Assignees
Labels
types Related to @cloudflare/workers-types

Comments

@shmuli9
Copy link

shmuli9 commented Jan 6, 2025

In latest version of wrangler types (4.20241230.0) there is a mismatch between the ExecutionContext type returned by PlatformProxy/getPlatformProxy and the type exported from @cloudflare/workers-types. This is causing type errors and appears to be an oversight/bug

// node_modules/.pnpm/@[email protected]/node_modules/@cloudflare/workers-types/index.ts
export interface ExecutionContext {
  waitUntil(promise: Promise<any>): void;
  passThroughOnException(): void;
  props: any;
}
// node_modules/.pnpm/[email protected]_@[email protected]/node_modules/wrangler/wrangler-dist/cli.d.ts
// this is the type used in PlatformProxy
declare class ExecutionContext {
    waitUntil(promise: Promise<any>): void;
    passThroughOnException(): void;
}

As you can see there is no props in the wrangler-dist types, but it is expected in @cloudflare/workers-types ressulting in typescript errors

To work around this I have had to make the following changes:

// load-context.ts
+ import type { ExecutionContext } from "@cloudflare/workers-types";

- type Cloudflare = Omit<PlatformProxy<Env>, "dispose">;
+ type Cloudflare = Omit<PlatformProxy<Env>, "dispose" | "ctx"> & {
+   ctx: ExecutionContext;
+ };
// vite.config.ts

import { getLoadContext } from "./load-context";

...

    remixCloudflareDevProxy({
-     getLoadContext
+      getLoadContext: ({ request, context }) =>
+       getLoadContext({
+          request,
+          context: {
+            cloudflare: {
+              env: context.cloudflare.env as Env,
+              cf: context.cloudflare.cf as IncomingRequestCfProperties,
+              ctx: context.cloudflare.ctx as ExecutionContext,
+              caches: context.cloudflare.caches,
+            },
+          },
+        }),
+    }),

Can this be addressed and fixed? Ideally PlatformProxy and @cloudflare/workers-types should match for all types

@shmuli9 shmuli9 added the types Related to @cloudflare/workers-types label Jan 6, 2025
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types Related to @cloudflare/workers-types
Projects
Status: Untriaged
Development

No branches or pull requests

2 participants