Closed as not planned
Description
Bug Report
π Search Terms
array filter narrow down
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about: x
β― Playground Link
Playground link with relevant code
π» Code
interface IFoo {
foo: boolean;
}
interface IBar {
bar: boolean;
}
const items: (IFoo | IBar)[] = [];
function isFoo(obj: unknown): obj is IFoo {
if (!obj) {
return false;
}
const candidate = obj as IFoo;
return typeof candidate.foo === `boolean`;
}
const fooItems = items.filter(item => isFoo(item));
for (const fooItem of fooItems) {
console.log(fooItem.foo); // error: Property foo does not exist on type IFoo | IBar
}
π Actual behavior
The fooItems
is of type IFoo | IBar
π Expected behavior
I would have expected fooItems
to be IFoo[]
.