couldn't use multer as router middleware with typescript
See original GitHub issueexample
// router.ts
import { Router } from "express";
import multer from "multer";
const router = Router();
const upload = multer({
storage: multer.memoryStorage()
});
router.post("/", [upload.any(), someEndpoint]); // this couldn't work
it says
No overload matches this call.
Overload 1 of 3, '(path: PathParams, ...handlers: RequestHandler<ParamsDictionary, any, any>[]): Router', gave the following error.
Argument of type 'RequestHandler<ParamsDictionary, any, any, any>[]' is not assignable to parameter of type 'RequestHandler<ParamsDictionary, any, any>'.
Type 'RequestHandler<ParamsDictionary, any, any, any>[]' provides no match for the signature '(req: Request<ParamsDictionary, any, any>, res: Response<any>, next: NextFunction): any'.
Overload 2 of 3, '(path: PathParams, ...handlers: RequestHandlerParams<ParamsDictionary, any, any>[]): Router', gave the following error.
Type 'RequestHandler<ParamsDictionary, any, any, any>' is not assignable to type 'ErrorRequestHandler<ParamsDictionary, any, any> | RequestHandler<ParamsDictionary, any, any>'.
Type 'RequestHandler<ParamsDictionary, any, any, any>' is not assignable to type 'RequestHandler<ParamsDictionary, any, any>'.
Type 'RequestHandler<ParamsDictionary, any, any, any>' provides no match for the signature '(req: Request<ParamsDictionary, any, any>, res: Response<any>, next: NextFunction): any'.
Overload 3 of 3, '(path: PathParams, subApplication: Application): Router', gave the following error.
Argument of type 'RequestHandler<ParamsDictionary, any, any, any>[]' is not assignable to parameter of type 'Application'.
Type 'RequestHandler<ParamsDictionary, any, any, any>[]' is missing the following properties from type 'Application': init, defaultConfiguration, engine, set, and 60 more.ts(2769)
or simply
Argument of type 'RequestHandler<ParamsDictionary, any, any, any>[]' is not assignable to parameter of type 'RequestHandler<ParamsDictionary, any, any>'.
my dependencies
"express": "^4.17.1",
"multer": "^1.4.2",
"@types/express": "^4.17.3",
"@types/multer": "^1.4.2",
any solution?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
couldn't use multer as router middleware with typescript ...
I use the type any explicitly to accept the middleware without errors as long as this problem is not fixed ... maybe it...
Read more >Multer handle error, problem with typescript types
I have the following code: import multer from "multer"; const upload = multer(). single('file'); router. post('/add', async (req, res) => { ...
Read more >How to Upload Files in Node.js using Multer
In a Node.js application, if there is a requirement to upload files to the server Multer is a good option. It can be...
Read more >How to Migrate Your App from Express to Fastify
Our example Express application only has one router, so we were able to migrate all of the routes in our application to use...
Read more >body-parser
Node.js body parsing middleware. Latest version: 1.20.1, ... Start using body-parser in your project by running `npm i body-parser`.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
moved here - https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43897
The Multer typs lives outside of the Express organisation, in DefinitelyTyped. I would recommend opening an issue there instead…