-
Notifications
You must be signed in to change notification settings - Fork 43
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
Lint error with TypeScript #35
Comments
Me too getting the same error. So I tried doing something like this: And then the linting error is gone. |
Any updates here? |
Can you share some code where you are getting this lint error? I think I know the solution |
Error message
Code: import express, { Request, Response } from 'express';
import 'express-async-errors';
async function asyncThrowError(): Promise<void> {
await Promise.all([]);
throw new Error('Test error');
}
async function main(): Promise<void> {
// TODO: remove later
await Promise.all([]);
const app = express();
app.get('/async-error', async (_request: Request, response: Response) => {
await asyncThrowError();
response.status(200).json({ success: true });
});
app.listen(40512);
}
main()
.then(() => {
// eslint-disable-next-line no-console
console.log('Application started');
})
.catch((error: Error) => {
// eslint-disable-next-line no-console
console.error('Application startup error', { error });
}); |
or
Let me know if one of them works. |
Same error . Plus , it does not tend to handle the async errors resulting from using Multer for file uploads |
EDIT: Unfortunately, fixing the
At the moment, this is above the time budget I have for the task. Maybe someone else would like to pick it up from here The partial solution
Create or extend an existing import type { Request, Response } from 'express';
import type { ParamsDictionary, Query } from 'express-serve-static-core';
import type { NextFunction } from 'express-serve-static-core';
declare module 'express-serve-static-core' {
export interface RequestHandler<
P = ParamsDictionary,
ResBody = any,
ReqBody = any,
ReqQuery = Query,
LocalsObj extends Record<string, any> = Record<string, any>
> {
(
req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>,
res: Response<ResBody, LocalsObj>,
next: NextFunction
): void | Promise<void>;
}
}
You are done! The type is fixed, so you will see no Comments on the implementation The conflict we are having here is with the type The feature we are using here is called merging interfaces it allows extending existing interfaces by re-declaring them So, here we duplicate the definition of the |
Using the async handler with this lib leads to the following lint error as the return type of async handler is a
Promise<>
and the expected one is just avoid
.Error Message:
I am not sure if the type definition of the express handler can be changed in this lib's definitions. Create a ticket just in case if it's possible.
The text was updated successfully, but these errors were encountered: