π Search Terms
filter type predicate
π Version & Regression Information
This only makes sense since TS5.5, when inferred type predicates were introduced.
β― Playground Link
https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAhjAvDA2gcigU2mgNDMAVwBtiBdAKAHoqY6YA9AfgotElgCMl4A6AMwCWxLACcAFAA8kAPhjSAhImRFSASmq16zVu2gxgPOAOFips+TCUqSxGADJ783tDiioEAOqCoAC3EYaGoaNPSMLBRAA
π» Code
const a = ['test', null]
const b = a.filter(x => x !== null)
const c = a.filter(x => x !== null && x.startsWith('t'))
π Actual behavior
On the above, the type of b is correctly inferred as string[], but the type of c is incorrectly inferred to (string | null)[]
π Expected behavior
The inferred type of c should string[], just like the inferred type of b.
Additional information about the issue
No response
π Search Terms
filter type predicate
π Version & Regression Information
This only makes sense since TS5.5, when inferred type predicates were introduced.
β― Playground Link
https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAhjAvDA2gcigU2mgNDMAVwBtiBdAKAHoqY6YA9AfgotElgCMl4A6AMwCWxLACcAFAA8kAPhjSAhImRFSASmq16zVu2gxgPOAOFips+TCUqSxGADJ783tDiioEAOqCoAC3EYaGoaNPSMLBRAA
π» Code
π Actual behavior
On the above, the type of
bis correctly inferred asstring[], but the type ofcis incorrectly inferred to(string | null)[]π Expected behavior
The inferred type of
cshouldstring[], just like the inferred type ofb.Additional information about the issue
No response