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.
Environment
@sentry/cloudflare: 10.65.0What is the problem?
The published
WorkerEntrypointConstructordeclaration exposes anEnvgeneric, but its constructor parameter ignores that generic and always usestypeof cloudflareEnv:As a result, passing a normal
WorkerEntrypoint<CustomEnv>class towithSentry()is rejected even though the callback and class use the same environment:The generic constraint on
withSentry()also uses the unconstrained/defaultWorkerEntrypointConstructor, which reinforces the mismatch.Expected behavior
WorkerEntrypointConstructor<Env>should acceptenv: Env, andwithSentry<Env>()/instrumentWorkerEntrypoint<Env>()should constrain the class usingWorkerEntrypointConstructor<Env>.Suggested declaration change
The
withSentry()union should similarly useWorkerEntrypointConstructor<Env>.Both
build/typesandbuild/types-ts3.8contain the same incorrect declaration. This is declaration-only; the 10.65 runtime behavior is not implicated.