-
Notifications
You must be signed in to change notification settings - Fork 727
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
BaseHandler handler method return type should take into account async handlers #1689
Comments
Hey @islazh, after having a look at the docs I don't think Express middleware handlers may be async. Having a look at express types: export interface RequestHandler<
P = ParamsDictionary,
ResBody = any,
ReqBody = any,
ReqQuery = ParsedQs,
LocalsObj extends Record<string, any> = Record<string, any>,
> {
// tslint:disable-next-line callable-types (This is extended from and can't extend from a type alias in ts<2.2)
(
req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>,
res: Response<ResBody, LocalsObj>,
next: NextFunction,
): void;
} Closing the issue now. Feel free to provide a code example of an asyncronous middleware working on express and I'll reopen the issue. EDIT: My bad, After having a look at the right types: export interface RequestHandler<
P = ParamsDictionary,
ResBody = any,
ReqBody = any,
ReqQuery = ParsedQs,
LocalsObj extends Record<string, any> = Record<string, any>,
> {
// tslint:disable-next-line callable-types (This is extended from and can't extend from a type alias in ts<2.2)
(
req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>,
res: Response<ResBody, LocalsObj>,
next: NextFunction,
): void | Promise<void>;
} It seems it's perfectly fine to provide an async handler |
Ok, I had a look at some articles and did some tests and it seems it's possible. Reopening the issue |
Fixed in inversify/inversify-express-utils#419. |
Is there an existing issue for this?
Current behavior
When creating a middleware with a handler, the handler's type is
Express middleware handlers may be async, so the return type should be
void | Promise<void>
Steps to reproduce
Create an async middleware handler with no-misused-promises turned on in ESLint config
Expected behavior
No ESLint errors
Possible solution
ESLint warning:
Package version
6.0.1
Node.js version
No response
In which operating systems have you tested?
Stack trace
No response
Other
No response
The text was updated successfully, but these errors were encountered: