Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript: Property 'name' does not exist on type 'FormDataEntryValue'

I have:

const file = formData.get('documents[]')

What type is file?

const file: FormDataEntryValue | null

I need to access to file?.name.

and i got:

Property 'name' does not exist on type 'FormDataEntryValue'.

like image 344
ValRob Avatar asked May 07 '26 14:05

ValRob


1 Answers

FormDataEntryValue is defined as an union of File and string: type FormDataEntryValue = File | string;

Thus you need to check first that the variable is indeed a File:

if (file instanceof File) {
  console.log(file.name);
}
like image 155
Eino Gourdin Avatar answered May 09 '26 04:05

Eino Gourdin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!