feat(cloudflare): Infer types correctly in workflows, handlers and DOs#18302
Open
feat(cloudflare): Infer types correctly in workflows, handlers and DOs#18302
Conversation
andreiborza
reviewed
Nov 24, 2025
Member
andreiborza
left a comment
There was a problem hiding this comment.
As discussed offline, this PR introduces breaking changes to the way generics are used and we can thus not merge this in this major.
Let's add this to the v11 milestone and fix it then, for now document what users have to do to get correct types.
This was referenced Nov 24, 2025
JPeer264
added a commit
that referenced
this pull request
Nov 26, 2025
This PR is a result of #18302. This ensures that the types are checked throughout the development of the Cloudflare SDK
JPeer264
added a commit
to getsentry/sentry
that referenced
this pull request
Jan 8, 2026
…05640) This adds the workaround until v11 is out. At the moment we have to explicitly set `(env: Env) => ...` in order to make the types work. This can be reverted (no must) when following is merged and released: getsentry/sentry-javascript#18302 reference: getsentry/sentry-javascript#18294 (comment)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #18294
Problem
In #18064 we fixed that any Cloudflare compatible app can be passed and the original types were passed (e.g. Hono). This caused a problem with the environment variables, as they were not inferred correctly. Those are two scenarios which should work:
optionCallbackinfers the correct types, based on the handler it was givenSolution
To ensure now that types are passed through (for e.g. Hono) and the all necessary types are inferred correctly, there is now only one source of truth for the types in the generics.
So instead of having
withSentry<Env = unknown, ..., T extends ExportedHandler<Env>>()it is nowwithSentry<Handler extends ExportedHandler<Env>>and whenever we would need the types, we actively infer them inside the function withInferEnv<Env>. With that approach we make sure both scenarios work properlyThe tests are now using the correct types as well (that was not the case and was the main issue why #18064 went through)
This is now also true for
.instrumentDurableObjectWithSentry()and.instrumentWorkflowWithSentry().