Skip to content

[express] Change RequestHandler return type to void#49677

Merged
typescript-bot merged 1 commit intoDefinitelyTyped:masterfrom
sonallux:express-request-handler-return-type
Nov 23, 2020
Merged

[express] Change RequestHandler return type to void#49677
typescript-bot merged 1 commit intoDefinitelyTyped:masterfrom
sonallux:express-request-handler-return-type

Conversation

@sonallux
Copy link
Copy Markdown
Contributor

Changes the return type of the RequestHandler and ErrorRequestHandler from any to void because express does not handle any returned value.

This will also make @typescript-eslint/no-misused-promises rule warn about request handlers that return a Promise, which might result in NodeJS's UnhandledPromiseRejectionWarning because express is not handling a rejected Promise.

Please fill in this template.

Select one of these and delete the others:

If changing an existing definition:

@typescript-bot typescript-bot added Critical package Untested Change This PR does not touch tests labels Nov 19, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Nov 19, 2020

@jsone-studios Thank you for submitting this PR!

This is a live comment which I will keep updated.

This PR doesn't modify any tests, so it's hard to know what's being fixed, and your changes might regress in the future. Have you considered adding tests to cover the change you're making? Including tests allows this PR to be merged by yourself and the owners of this module. This can potentially save days of time for you.

1 package in this PR

Code Reviews

This PR can be merged once it's reviewed.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Most recent commit is approved by type definition owners or DT maintainers

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 49677,
  "author": "jsone-studios",
  "headCommitAbbrOid": "1f898c8",
  "headCommitOid": "1f898c876e2751345fdce3630c4f5f890337e8e9",
  "stalenessInDays": 0,
  "lastPushDate": "2020-11-19T09:22:11.000Z",
  "lastCommentDate": "2020-11-23T20:43:30.000Z",
  "maintainerBlessed": true,
  "mergeOfferDate": "2020-11-23T20:41:25.000Z",
  "mergeRequestDate": "2020-11-23T20:43:30.000Z",
  "mergeRequestUser": "dwrss",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "express-serve-static-core",
      "kind": "edit",
      "files": [
        {
          "path": "types/express-serve-static-core/index.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "borisyankov",
        "19majkel94",
        "kacepe",
        "micksatana",
        "samijaber",
        "JoseLion",
        "dwrss",
        "andoshin11"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "dwrss",
      "date": "2020-11-21T15:03:02.000Z",
      "isMaintainer": false
    }
  ],
  "ciResult": "pass"
}

@typescript-bot
Copy link
Copy Markdown
Contributor

🔔 @borisyankov @19majkel94 @kacepe @micksatana @samijaber @JoseLion @dwrss @andoshin11 — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot
Copy link
Copy Markdown
Contributor

👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings.

Let’s review the numbers, shall we?

Comparison details 📊
master #49677 diff
Batch compilation
Memory usage (MiB) 69.5 73.6 +5.9%
Type count 10546 10546 0%
Assignability cache size 2086 2086 0%
Language service
Samples taken 137 137 0%
Identifiers in tests 137 137 0%
getCompletionsAtPosition
    Mean duration (ms) 339.1 335.9 -1.0%
    Mean CV 11.2% 10.7%
    Worst duration (ms) 581.6 564.5 -2.9%
    Worst identifier send send
getQuickInfoAtPosition
    Mean duration (ms) 359.0 364.2 +1.5%
    Mean CV 11.0% 11.3%
    Worst duration (ms) 587.7 606.5 +3.2%
    Worst identifier res res

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added the Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. label Nov 19, 2020
@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner labels Nov 21, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

@jsone-studios Everything looks good here. Great job! I am ready to merge this PR (at 1f898c8) on your behalf.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@borisyankov, @19majkel94, @kacepe, @micksatana, @samijaber, @JoseLion, @dwrss, @andoshin11: you can do this too.)

@dwrss
Copy link
Copy Markdown
Contributor

dwrss commented Nov 23, 2020

Ready to merge

@typescript-bot typescript-bot merged commit 7a41e02 into DefinitelyTyped:master Nov 23, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

I just published @types/[email protected] to npm.

@sonallux sonallux deleted the express-request-handler-return-type branch November 24, 2020 06:14
@Mister-Hope
Copy link
Copy Markdown
Contributor

Mister-Hope commented Nov 26, 2020

@jsone-studios @dwrss I am running in to expressjs/express#4467

So how should I bypass the type check with this PR?

My opinion is that the return type should be void | Promise<void>.

Could you fix it? @jsone-studios

@sonallux
Copy link
Copy Markdown
Contributor Author

sonallux commented Nov 26, 2020

So how should I bypass the type check with this PR?

You should not bypass the type check. You must handle the case when getManifest() is returning a rejected promise, otherwise you risk that your request stays open unanswered and in the future, your NodeJS process will terminate because of an unhandled promise rejection.

You can add an explicit .catch(...) handler to the returned promise

app.get("/manifest.webmanifest", (_req, res) => {
  getManifest(pwaOptions)
    .then(result => res.send(result))
    .catch(error => res.status(500).send('Unexpected error'))
});

or use the express-async-handler or the express-async-router library.

@Mister-Hope
Copy link
Copy Markdown
Contributor

Thanks for the answer❤

owenlow pushed a commit to owenlow/DefinitelyTyped that referenced this pull request Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Critical package Owner Approved A listed owner of this package signed off on the pull request. Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. Self Merge This PR can now be self-merged by the PR author or an owner Untested Change This PR does not touch tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants