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(types): return void promises from the express receiver middleware parser #2141

Merged
merged 2 commits into from
Jun 19, 2024

Conversation

zimeg
Copy link
Member

@zimeg zimeg commented Jun 19, 2024

Summary

This PR fixes type errors found in #2140 caused by the latest floating version of @types/express:

Error: src/receivers/ExpressReceiver.ts(446,3): error TS2322: Type '(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => Promise<...>' is not assignable to type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
  Type 'Promise<void | Response<any, Record<string, any>, number>>' is not assignable to type 'void | Promise<void>'.
    Type 'Promise<void | Response<any, Record<string, any>, number>>' is not assignable to type 'Promise<void>'.
      Type 'void | Response<any, Record<string, any>, number>' is not assignable to type 'void'.
        Type 'Response<any, Record<string, any>, number>' is not assignable to type 'void'.
Error: src/receivers/ExpressReceiver.ts(548,3): error TS2322: Type '(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => Promise<...>' is not assignable to type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
  Type 'Promise<void | Response<any, Record<string, any>, number>>' is not assignable to type 'void | Promise<void>'.

Notes

I'm pretty sure sending res.send() then returning after is equivalent to what existed before. Just without the typing strangeness.

The final next() without a return seems alright too IMO since this function returns as a Promise<void>.

Requirements

@zimeg zimeg added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch TypeScript-specific dependencies Pull requests that update a dependency file labels Jun 19, 2024
@zimeg zimeg added this to the 3.19.0 milestone Jun 19, 2024
@zimeg zimeg self-assigned this Jun 19, 2024
Copy link

codecov bot commented Jun 19, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Project coverage is 82.00%. Comparing base (dcccf9d) to head (03e3321).

Files Patch % Lines
src/receivers/ExpressReceiver.ts 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2141      +/-   ##
==========================================
- Coverage   82.03%   82.00%   -0.03%     
==========================================
  Files          18       18              
  Lines        1536     1539       +3     
  Branches      442      442              
==========================================
+ Hits         1260     1262       +2     
- Misses        178      179       +1     
  Partials       98       98              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

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

Weird but fine! As long as tests pass, :shipit:

Thanks for fixing this!

@zimeg
Copy link
Member Author

zimeg commented Jun 19, 2024

@filmaj so much agreement with this weirdness... But appreciate the fast review! I'll keep an eye out for strangeness that comes from this, though I'm confident in our tests 🙏

}
}

return next();
Copy link
Member Author

Choose a reason for hiding this comment

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

This is somewhat questionable to me but it raises this type error for me:

return next();     ■ Async arrow function expected no return value.

@zimeg zimeg merged commit 43e4386 into slackapi:main Jun 19, 2024
8 checks passed
@zimeg zimeg deleted the zimeg/fix-express-types branch June 19, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented dependencies Pull requests that update a dependency file semver:patch TypeScript-specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants