Skip to content

Commit 3deeecd

Browse files
authored
fix(cloudflare): Ensure types for cloudflare handlers (#18064)
This is fixing type safety for Cloudflare handlers. With that change the tests have the correct types and vitest can run through 🚀
1 parent fbadeb8 commit 3deeecd

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sentry:registry=http://127.0.0.1:4873
2+
@sentry-internal:registry=http://127.0.0.1:4873

dev-packages/e2e-tests/test-applications/cloudflare-hono/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"cf-typegen": "wrangler types --env-interface CloudflareBindings",
99
"test:build": "pnpm install && pnpm build",
1010
"//": "Just checking if it builds correctly and types don't break",
11-
"test:assert": "pnpm typecheck"
11+
"test:assert": "pnpm typecheck && vitest run ."
1212
},
1313
"dependencies": {
1414
"@sentry/cloudflare": "latest || *",

packages/cloudflare/src/handler.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ import { copyExecutionContext } from './utils/copyExecutionContext';
2929
* @returns The wrapped handler.
3030
*/
3131
// eslint-disable-next-line complexity
32-
export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostMetadata = unknown>(
33-
optionsCallback: (env: Env) => CloudflareOptions,
34-
handler: ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata>,
35-
): ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata> {
32+
export function withSentry<
33+
Env = unknown,
34+
QueueHandlerMessage = unknown,
35+
CfHostMetadata = unknown,
36+
T extends ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata> = ExportedHandler<
37+
Env,
38+
QueueHandlerMessage,
39+
CfHostMetadata
40+
>,
41+
>(optionsCallback: (env: Env) => CloudflareOptions, handler: T): T {
3642
setAsyncLocalStorageAsyncContextStrategy();
3743

3844
try {

0 commit comments

Comments
 (0)