Background
I'm making a simple website in which a user can upload an image. I'm using Node/React/Multer/Typescript.
Problem
app.post('/admin/uploads', async (req, res) => {
uploadHandler(req, res, (err) => {
...
if ( req.files.companyImage !== undefined ) {
...
}
res.sendStatus(201);
});
});
typescript intellisense shows error like below.
Property 'companyImage' does not exist on type '{ [fieldname: string]: File[]; } | File[]'.
Property 'companyImage' does not exist on type '{ [fieldname: string]: File[]; }'.ts(2339)
But, I cannot understand why this is error. I think files object has type { [fieldname: string]: File[]; }. This means files object can have property which is string.
So I test with simple example.
type myType = {
[fieldName: string]: number
}
let req: myType = {
a: 333,
b: 344
}
console.log(req.a);
console.log(req.c); // undefined but intellisense don't show error
I don't know why files object cannot have companyImage property.
Check please.