Skip to content

Cloudflare WorkerEntrypointConstructor ignores its Env generic #22233

Description

@matthew-gizmo

Environment

  • @sentry/cloudflare: 10.65.0
  • TypeScript: 7.0.2
  • Wrangler: 4.110.0
  • Cloudflare Workers runtime types: 4.20260410.1

What is the problem?

The published WorkerEntrypointConstructor declaration exposes an Env generic, but its constructor parameter ignores that generic and always uses typeof cloudflareEnv:

export type WorkerEntrypointConstructor<
  Env = typeof cloudflareEnv,
  Props = {}
> = new (
  ctx: ExecutionContext,
  env: typeof cloudflareEnv
) => InstanceType<typeof WorkerEntrypoint<Env, Props>>;

As a result, passing a normal WorkerEntrypoint<CustomEnv> class to withSentry() is rejected even though the callback and class use the same environment:

interface CustomEnv {
  SENTRY_DSN: string;
  MY_BINDING: KVNamespace;
}

class MyWorker extends WorkerEntrypoint<CustomEnv> {
  fetch() {
    return new Response('ok');
  }
}

export default Sentry.withSentry(
  (env: CustomEnv) => ({ dsn: env.SENTRY_DSN }),
  MyWorker
);

The generic constraint on withSentry() also uses the unconstrained/default WorkerEntrypointConstructor, which reinforces the mismatch.

Expected behavior

WorkerEntrypointConstructor<Env> should accept env: Env, and withSentry<Env>() / instrumentWorkerEntrypoint<Env>() should constrain the class using WorkerEntrypointConstructor<Env>.

Suggested declaration change

export type WorkerEntrypointConstructor<
  Env = typeof cloudflareEnv,
  Props = {}
> = new (
  ctx: ExecutionContext,
  env: Env
) => InstanceType<typeof WorkerEntrypoint<Env, Props>>;

export declare function instrumentWorkerEntrypoint<
  Env = typeof cloudflareEnv,
  T extends WorkerEntrypointConstructor<Env> = WorkerEntrypointConstructor<Env>
>(
  optionsCallback: (env: Env) => CloudflareOptions | undefined,
  WorkerEntrypointClass: T
): T;

The withSentry() union should similarly use WorkerEntrypointConstructor<Env>.

Both build/types and build/types-ts3.8 contain the same incorrect declaration. This is declaration-only; the 10.65 runtime behavior is not implicated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions