π Search Terms
"Inferred Type Predicates"
π Version & Regression Information
5.6.0-dev.20240801
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240801#code/C4TwDgpgBA8lC8UDeUDWEQC4oGdgCcBLAOwHMoBfAbgCgBjAe2LygYCMArHbACjgB8oxAK4AbUQEoA2gF0EUKSnRYoAcgCGqygBpkaDNlVstFXSPEzajZsCgAzQqOAR8EACYBGeey4A6B04uPDgIAHy4UACEiOaSVFAA9AmwsvRMLAHOrm4ATN6cOP6OWcFhEdFCYqJQAGQ1uL7KCIgaqhLxSVB8UIKx0jJpNvbFLu4AzPl+mUEh8OEhFX1Fgfilcw1N8C2a7YnJMKlAA
π» Code
type O = { key: string };
const objs: (O | null)[] = [{ key: 'a' }, { key: 'b' }, null];
const filtered1 = objs.filter(s => s != null); // O[]
const filtered2 = objs.filter(s => s != null && s.key == 'a'); // (O | null)[]
const filtered3 = objs.filter(s => s != null).filter(s => s.key == 'a'); // O[]
π Actual behavior
The type inferred for filtered2 is (O | null)[] instead of O[].
π Expected behavior
I would expect filtered2 to have the inferred type O[], similar to filtered1 and filtered3.
Additional information about the issue
No response