Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): Fix tRPC middleware typing #9540

Merged
merged 1 commit into from
Nov 14, 2023
Merged

fix(node): Fix tRPC middleware typing #9540

merged 1 commit into from
Nov 14, 2023

Conversation

lforst
Copy link
Member

@lforst lforst commented Nov 13, 2023

Fixes #9536

The issue was that the middleware returned a function that returned Promise<Promise<T>> instead of Promise<T>. To fix this we take care not to modify the return value at all and just return T.

We could have also casted to any I think but this is probably cleaner.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@lforst lforst requested review from mydea, Lms24 and AbhiPrasad November 13, 2023 12:02
captureError(e);
}
}
let maybePromiseResult;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not directly related and nothing to do, but I feel like we've written this or very similar code a lot of times by now, maybe we can find a way to extract this into some util function that we can reuse 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah agreed. It's like a promise aware try catch. Would definitely make sense to extract!

@@ -326,7 +327,7 @@ interface SentryTrpcMiddlewareOptions {

interface TrpcMiddlewareArguments<T> {
path: string;
type: 'query' | 'mutation' | 'subscription';
type: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we broading this on purpose here (just checking)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are not depending on any of the direct strings here (just dumping what's in type onto the event) and I figured that if trpc adds more types we will break typing again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v7.80.0 breaks tRPC middleware handler (Typescript)
2 participants