Type definitions are wrong, don't allow Promise to be returned (caught by @typescript-eslint)
See original GitHub issueEnv:
TypeScript: 4.1.3
Express: 4.17.1
Node: 14.16.0
@typescript-eslint/eslint-plugin: 4.17.0
@typescript-eslint/parser: 4.17.0
Repro:
import express from 'express';
import createRouter from 'express-promise-router';
export const router = createRouter();
router.get(
'/',
async (req: express.Request, res: express.Response): Promise<string> => {
res.sendStatus(200);
},
);
export const server = express().use(router);
Produces:
Promise returned in function argument where a void return was expected.eslint@typescript-eslint/no-misused-promises
This is because the type definitions from express-promise-router
are just using the express.Router
interface which doesn’t support Promises (the very reason why this package exists).
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9 (6 by maintainers)
Top Results From Across the Web
no-misused-promises | typescript-eslint
This rule forbids providing Promises to logical locations such as if statements in places where the TypeScript compiler allows them but they are...
Read more >node.js - TypeScript/Eslint throwing a 'Promise returned' error ...
I found a solution that doesn't involves using then() and let you use the abstraction of async without getting cursed by the eslint, ......
Read more >Rules - ESLint - Pluggable JavaScript Linter
Rules in ESLint are grouped by type to help you understand their purpose. ... Disallow returning values from Promise executor functions. Categories:.
Read more >The starting point for learning TypeScript
A great first read for your daily TS work. The TypeScript Handbook · The Basics · Everyday Types · Narrowing · More on...
Read more >No Floating Promises: an eslint rule to prevent async code errors
If you're working in TypeScript, there's already a handy solution baked into @typescript-eslint - just activate the rule @typescript-eslint/no- ...
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
There is nothing to merge. I wrote a failing test case but actually solving this isn’t trivial as (as far as I can tell) we need to duplicate lots of definitions from
@types/express
. I haven’t had the time to look into this again since then.I think i understand what you mean now. It’s not a TypeScript error, it’s that ts eslint thinks the promise is unused. I’ll have a look later.