Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!