Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

411
Visualizações
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'.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

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);
}
about 4 years ago · Juan Pablo Isaza Relatório

0

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
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda