Description
Looking at #5744, the PolymorphicRequest
type seems wrong or rather dangerous to me. IMO this type needs to be a union (|
) instead of an intersection (&
).
sentry-javascript/packages/types/src/polymorphics.ts
Lines 16 to 21 in 9862a32
Why?: With an intersection, we're creating a new type that none of the frameworks support. This might lead to us making wrong assumptions about what a request might look like. For example, let's say a ExpressRequest
has a field someField: string
, but none of the others have someField
, TS will still allow us to access someField
, even though none of the others have it. (Not the best example since all of the fields we define are optional - I know... but still valid)
What would I do?: Replace this type with a union and remove the optional fields from the framework-specific Request
types (unless they're actually optional). That way we can apply proper type-safe type narrowing in all the places where we accept a PolymorphicRequest
.
We probably don't have any actual errors because of this, but in its current state, this is very error-prone.
I am opening this in a separate issue so we can discuss this regardless of open PRs.