Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

336
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda