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.

Type definitions are wrong, don't allow Promise to be returned (caught by @typescript-eslint)

See original GitHub issue

Env:

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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
mormahrcommented, Sep 25, 2021

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.

1reaction
mormahrcommented, Mar 21, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

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