question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ExpressJS 5 - Promise returned in function argument where a void return was expected.

See original GitHub issue

I am trying to use async and await in Typescript with ExpressJS 5 beta 1 and getting the following error:

Promise returned in function argument where a void return was expected.eslint[@typescript-eslint/no-misused-promises](https://typescript-eslint.io/rules/no-misused-promises)

I had anticipated this would no longer be the case in ExpressJS 5, as noted by the ESLint maintainers: https://github.com/standard/eslint-config-standard-with-typescript/issues/613

Have I missed something, or is this still not handled in Express 5?

function testFunction() {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve('test')
    }, 1000)
  })
}

router.get('/v1/sdk/device', async (_req, res) => {
  const test = await testFunction()
  console.log(test)
  res.send()
})
Screenshot 2022-04-18 at 09 05 50

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
maggie0002commented, Apr 18, 2022

I stumbled across this on my travels: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/50871

I think that is significant enough to suggest it is typings related. The typings have changed a lot since that was pushed, so hasn’t been easy to test. Not really sure what to do with it either, I imagine it is pending a community contribution of a v5 typings. I will update that post, and see what happens. In the meantime, will just have to work around the error and take confidence in knowing that it is in theory still working as expected now in v5.

0reactions
maggie0002commented, Apr 18, 2022

Much appreciated. Let me see if I can put together an example. Not 100% sure I can because it may be somewhat related to visual studio code and that’s harder to replicate across systems. But worth a shot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promise returned in function argument where a void return ...
An async function always returns a promise, so it can't be passed where a void function is expected. Why not just call the...
Read more >
Using Express.js Routes for Promise-based Error Handling
This Express.js tutorial shows you how to centralize Express.js error ... object has a .length property describing how many parameters the function expects....
Read more >
async function returning Promise<void> successfully ... - Reddit
Hi, Here is a playground with my issue. In short, I'm trying to understand why public async func(): Promise<void> {} is a valid...
Read more >
5.x API - Express.js
This is a built-in middleware function in Express. It parses incoming requests with JSON payloads and is based on body-parser. Returns middleware that...
Read more >
Promise.prototype.then() - JavaScript - MDN Web Docs
The then() method of a Promise object takes up to two arguments: callback functions for the fulfilled and rejected cases of the Promise....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found