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'.
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);
}
Property 'name' does not exist on type 'FormDataEntryValue'.
As error says, looks like key passed in the FormData.get() or the name property in file variable doesn't exist.
The get() method of the FormData interface always returns the first value associated with a given key from within a FormData object.
Hence, As per your code. Looks like documents is an array of object. Hence, you can access the name by file[0]?.name instead of file?.name
formData.append('documents', '[{name: "alpha"}]');
const file = formData.get('documents')
const fileName = file[0]?.name // returns alpha