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

296
Vistas
Function doesn't work when tested with typescript?

I have a strange problem. I have the below function in js:

const removeDuplicates = (inputData) => {
  return [
    ...new Map(inputData.map((data) => [JSON.stringify([data.x, data.y, data.v]), data])).values()
  ];
};

And I'm testing it like so in a jest typescript test:

it('removeDuplicates', () => {
    const expectedObject = [
    { x: 'G', y: 'B', v: '12345' },
    { x: 'A', y: 'L', v: '12345' },
    { x: 'A', y: 'W', v: '123' },
    { x: 'A', y: 'W', v: '1234' }
];
    
    
    const inputData = [
      { x: 'G', y: 'B', v: '12345' },
      { x: 'A', y: 'L', v: '12345' },
      { x: 'A', y: 'L', v: '12345' },
      { x: 'A', y: 'W', v: '123' },
      { x: 'A', y: 'W', v: '1234' },
      { x: 'A', y: 'W', v: '1234' }
    ];
    expect(removeDuplicates(inputData)).toEqual(expectedObject);
  });

When the test is in a js file it passes, when I convert the test file to a ts file it, fails and the function returns nothing! Any ideas?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Seems like the compiler doesn't like it without the compiler option ''--downlevelIteration'. Did you set this?

Type 'IterableIterator<unknown>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.ts(2569)

You could use Array.from instead:

type MyThing = { x: string; y: string; v: string };

const removeDuplicates = (inputData: MyThing[]): MyThing[] =>
  Array.from(
    new Map(
      inputData.map((data) => [JSON.stringify([data.x, data.y, data.v]), data])
    ).values()
  );

You should also consider using an external library for such trivial tasks. E.g. Ramda's uniq function should do exactly the same.

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