fix(cloudflare): Use correct env types for withSentry#19836
Open
fix(cloudflare): Use correct env types for withSentry#19836
Conversation
d781f4c to
5fbcf2d
Compare
Contributor
size-limit report 📦
|
chargome
reviewed
Mar 17, 2026
| */ | ||
| export function withSentry< | ||
| Env = unknown, | ||
| Env = typeof env, |
Member
There was a problem hiding this comment.
q: Isn't this theoretically breaking?
Member
Author
There was a problem hiding this comment.
I don't really see this as a breaking change, as Env is only there so it gets inferred by the third generic entry, which I think just grew over time. So there are couple of usages and non of them look breaking to me:
// sets "Env" directly, so it isn't affected at all
withSentry<{ myEnv: string }>()
// "Env" is manually set, which means it is the same type now
withSentry((env: Env) => ({}), exportedHandler)
// Not setting anything, this wasn't working before, but works with this PR
withSentry(env => ({}), exportedHandler)It could also be that people used not existing env variables, which wouldn't work as the exported handler is already typed, as documented, with the env usually (which is the same behavior with and without this PR):
const exportedHandler = { fetch() {} } satisfies ExportedHandler<Env>
withSentry((env: { notExistingEnv: string }) => ({}), exportedHandler)
^^^^^^^^^^^^^^^
chargome
approved these changes
Mar 18, 2026
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
closes JS-1202
By not using
unknownbut going directly to theenvexport ofcloudflare:workers, this should resolve the typing issue, without changing the current generic API (as proposed in #18302).The test proofs that when changing the Cloudflare globals, that this works OOTB now.