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

159
Visualizações
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 à 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