feat(cloudflare): Infer types correctly in workflows, handlers and DOs #18302
+106
−31
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().