I have the following code:
import multer from "multer";
const upload = multer().single('file');
router.post('/add', async (req, res) => {
upload(req, res, async (err: any) => {
if (err) {
res.status(500).send(err.toString())
}
else {
res.status(200).send(await addMedia(req.file.filename))
}
})
});
I am trying to determine the type, so I want to replace any by an appropriate Error type. When I try to replace it with MulterError, I get following error :
Argument of type '(err: MulterError) => Promise' is not assignable to parameter of type 'NextFunction'. Types of parameters 'err' and 'deferToNext' are incompatible. Type 'string' is not assignable to type 'MulterError'.
unknown does not work due to the .toString(). string does work, but it is definitely not the correct type, as logging it shows me that I have a MulterError.
I don't completely understand what the 3rd parameter of the upload function is either - so that may be my issue.