-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type definitions are wrong, don't allow Promise to be returned (caught by @typescript-eslint) #230
Comments
Hi, we don’t send out values returned by the promises. We want to avoid values being implicitly returned by a promise chain to end up at the client. It would also be hard to support status codes and the like. We run the promises and forward errors, but you have to send the values yourself. See the section „Why aren't promise values sent to the client“ in the readme. If you want to send a string, like I assume you wanted in your example, you call import express from 'express';
import createRouter from 'express-promise-router';
export const router = createRouter();
router.get(
'/',
async (req: express.Request, res: express.Response): Promise<void> => {
res.status(200).send('Hello World');
},
);
export const server = express().use(router); I hope this cleared up any confusion. As an aside: |
Thanks for the reply, @mormahr. I'm aware of the Promise/response behavior, but this is not the issue. As soon as you mark a function with the |
Yes and that's correct, but it has to return |
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. |
Yep, exactly. It states that because the return signature from the |
I added a failing test case in #231. |
Would be nice to merge this so consumers don't have to disable the lint rule for every |
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 |
From what I've tried, the problem is essentially that in the type definition of I might contact the maintainers of the |
Env:
Repro:
Produces:
This is because the type definitions from
express-promise-router
are just using theexpress.Router
interface which doesn't support Promises (the very reason why this package exists).The text was updated successfully, but these errors were encountered: