Router.get method in Express is called with the wrong type: The request handler is mistaken for a child application #6305
Closed
hyfhaozero
started this conversation in
General
Replies: 2 comments 3 replies
-
Could you please provide the version of Express, TypeScript, and the version of the types you are using? |
Beta Was this translation helpful? Give feedback.
2 replies
-
If you are using types for 5.x, then request handlers must return More details: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Note: I use the typescript
When using the tokenRouter.get method in the auth/token.ts file to define a route handler, the TypeScript compiler throws a type mismatch error. The error message is as follows:
The console messages
auth/token.ts:15:30 - error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type '(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>) => Response<...> | undefined' is not assignable to parameter of type 'Application<Record<string, any>>'.
Type '(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>) => Response<...> | undefined' is missing the following properties from type 'Application<Record<string, any>>': init, defaultConfiguration, engine, set, and 63 more.
15 tokenRouter.get('/getToken', function(req: Request, res: Response) {
~~~~~~~~
node_modules/@types/express-serve-static-core/index.d.ts:168:5
168 (path: PathParams, subApplication: Application): T;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The last overload is declared here.
Found 1 error in auth/token.ts:15
Code part
Beta Was this translation helpful? Give feedback.
All reactions