The following code is fine but if you uncomment the last line ts will give an error. Seems like .filter() throws away the already inferred type from the previous step which doesn't make sense to me. Please explain how ts works here and suggest a solution.
type ItemIds =
| 'foo'
| 'bar';
interface Item {
id: ItemIds;
};
const items: Item[] = [
{
id: 'foo',
},
{
id: 'bar',
}
]
//.filter((item) => true)