Uh oh!
There was an error while loading. Please reload this page.
fix(cloudflare)!: add better type handling for additional context - #15276
fix(cloudflare)!: add better type handling for additional context#15276chanceaclark wants to merge 1 commit into
Conversation
BREAKING CHANGE: Updates the cloudflare withSentry handler generic type to allow passing in additional types used by ExportedHandler. Before: ``` Sentry.withSentry<ExportedHandler<Env>>(...) ``` After: ``` Sentry.withSentry<Env>(...) ```
Lms24
commented
Feb 6, 2025
Hi @chanceaclark thanks for opening this PR! Would you mind sharing a reproducible example where you get a type error with the currently typed If we can understand the concrete use case better, we can make a better decision how to proceed with this PR. Maybe a way forward is also to export a new API with the adjusted types if we can't avoid breaking. We'll see. |
Lms24
commented
Feb 6, 2025
By the way, we have an e2e test application in the repo. Feel free to add another handler that would throw the type error with the current type definition. This can help us understand the problem and at the same time adds a regression test, thanks :) |
chanceaclark
commented
Feb 13, 2025
Hey @Lms24 sorry to get back to you so late. Added a test case in the package and made a sample repo with the type error I was running into: Test case:develop...chanceaclark:sentry-javascript:test/cf-additional-types Similarly it happens even when using the generic instead of the I also tried adjusting the sentry lib types to not make it a breaking change but the same issue was occuring, for example these: exportdeclarefunctionwithSentry<EextendsExportedHandler<unknown,unknown,unknown>>(optionsCallback: (env: ExtractEnv<E>)=>CloudflareOptions,handler: E): E;// orexportdeclarefunctionwithSentry<EextendsExportedHandler<any,any,any>>(optionsCallback: (env: ExtractEnv<E>)=>CloudflareOptions,handler: E): E;// orexportdeclarefunctionwithSentry<EextendsExportedHandler>(optionsCallback: (env: ExtractEnv<E>)=>CloudflareOptions,handler: E): E;The only thing I found that seems to work is setting the generic with a default type, but that doesn't constrain the type which I don't think we want. I guess my solution in the PR doesn't constrain the type either though 😅 exportdeclarefunctionwithSentry<E=ExportedHandler>(optionsCallback: (env: ExtractEnv<E>)=>CloudflareOptions,handler: E): E; |
Found this as I'm also getting type mismatch errors in our monorepo, unfortunately can't share a repro right now tho 😇 I'm getting On first glance the proposed PR looks promising 🤓 |
chanceaclark
commented
Mar 6, 2025
I'm tempted to go with the follow so it's not a breaking change: @Lms24 is this something you'd be comfortable with too? |
Lms24
commented
Mar 10, 2025
@chanceaclark sorry for the late reply (I've been out for a couple of days). This sounds reasonable to me but I'll leave this up to @AbhiPrasad to give the final okay. Feel free to make the change though as we won't merge in a breaking change anytime soon. |
chanceaclark
commented
May 12, 2025
Closing as it was done in #16233 |

What/Why?
Adds better handling of Cloudflare context for types. Using

anyandunknownin an interface was causing type mismatch, so even though it's more verbose, we should match the types needed from Cloudflare:Noticed a v9 is coming soon, so thought it's a good opportunity to add a BC now.
BREAKING CHANGE:
Updates the cloudflare withSentry handler generic type to allow passing in additional types used by ExportedHandler.
Before:
After:
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint) & (yarn test).