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 ?