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

339
Visualizações
Eslint error with Array forEach iteration: Promise returned in function argument where a void return was expected

I'm trying to write a function to do transformation for Files which are not throwing any exception like a method below. I'm seeing ESLint error - "Eslint: Promise returned in function argument where a void return was expected.". What can be done to fix this eslint?

Note we would skip the files which will throw Error. Those are appropriately logged though.

export async function createDataFromFiles(inputFiles: File[]): Promise<Data[]> {
        const result: Data = [];
    
        inputFiles.forEach(
            async (file) => {
                const imageData = new DataView(await file.arrayBuffer());
                const blobUrl = URL.createObjectURL(new Blob([imageData]));
                try {
                    const dimension = await getDimensionsFromImageUrl(blobUrl);
                    answer.push({ imageData, dimension });
                } finally {
                    URL.revokeObjectURL(blobUrl);
                }
            }
        );
    
        return Promise.all(answer);
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is because of the signature of Array.forEach:

forEach(callbackfn: (value: undefined, index: number, array: undefined[]) => void): void.

The callbackFn has type void, but when using async the function implicitly returns a Promise.

You can avoid this warning by using an ordinary for...of loop:

export async function createDataFromFiles(inputFiles: File[]): Promise<Data[]> {
    const result: Data = [];

    for (const file of inputFiles) {
        const imageData = new DataView(await file.arrayBuffer());
        const blobUrl = URL.createObjectURL(new Blob([imageData]));
        try {
            const dimension = await getDimensionsFromImageUrl(blobUrl);
            answer.push({ imageData, dimension });
        } finally {
            URL.revokeObjectURL(blobUrl);
        }
    }

    return Promise.all(answer);
}
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