ExpressJS 5 - Promise returned in function argument where a void return was expected.
See original GitHub issueI 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()
})
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.