richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.52k stars 259 forks source link

Property 'userImage' does not exist on type '{ [fieldname: string]: File[]; } | File[]'. Property 'userImage' does not exist on type 'File[]' #332

Open faruuhan opened 1 year ago

faruuhan commented 1 year ago

How to fix this ? i'm using typescript

image

flolu commented 1 year ago
import {FileArray, UploadedFile} from 'express-fileupload'

const reqFile = (req.files as FileArray).file as UploadedFile
if (!reqFile) throw 'No file to upload'

// do something
jjarvela commented 5 months ago
import {FileArray, UploadedFile} from 'express-fileupload'

For me this gives:

Conversion of type '{ [fieldname: string]: File[]; } | File[]' to type 'FileArray' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type 'File[]' is not comparable to type 'FileArray'.
    Index signature for type 'string' is missing in type 'File[]'.ts(2352)
(property) Express.Request.files?: {
    [fieldname: string]: Express.Multer.File[];
} | Express.Multer.File[]

Quickfix for this is : const fileArray = (req.files as unknown as FileArray)