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

164
Vistas
Why cannot typescript infer anonymous interfaces outside chained method?

I do not understand why Typescript is not inferring my property names in the following example.
Example 1: Can infer type and property name

//In this example TS recognizes the return type of my first map as {teamId:string,teamCode:string}[]
const foo = something.map(ele=> {
      return {
        teamId: someDict[ele.blah.id.entityId].team.id.entityId,
        teamCode: someDict[cfg.blah.id.entityId].code,
      }
    }).filter(ele => !currentTeamIds.includes(ele.teamId)).map(ele => ele.teamCode)

Example 2: Cannot infer property type and name when the filter is pulled into a different statement

//In this example TS marks foo as any instead of the type mentioned above.
const foo = something.map(ele=> {
      return {
        teamId: someDict[ele.blah.id.entityId].team.id.entityId,
        teamCode: someDict[cfg.blah.id.entityId].code,
      }
    })
const bar = foo.filter(ele => !currentTeamIds.includes(ele.teamId)).map(ele => ele.teamCode)

I thought the two examples would be equivalent. Why cannot TS infer my types when I seperate the filter out and break it from the chain ?

about 4 years ago · Juan Pablo Isaza
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