π Search Terms
Inferred Type Predicates Boolean
π Version & Regression Information
This is a new issue introduced in 5.5
β― Playground Link
https://www.typescriptlang.org/play/?isolatedDeclarations=true#code/PTAEGEHsCdoUwMYBcA2BPUBLAdgMztAM6hJoAOcoAhsYUtDgOYBQCk2doA7jANaEAuUHQbZGAbQC6oALyhxAOiUBBWFTQAKAKwBKSc1CHQCgLZUyGgG6yAfKADeBo88y5QV0AFIATLJlyABh0HJ2cw0HgkAFdobFAAcipheiZ4gG5QsIBfZkznSJi47CiUFAznLJ1MhVxMFCQCDxk7AEIWyx0M5hBQABFIOEJseKRuPlBcGGFIE0p4GnZQOEs4OKQAC0goxnWsJGIAIxpMBCpSjA3KQipZ1nZOABMBoaQAdT4ARiERJilZeSUClU0HU2j01TMFmszRC4UMrnc1h8fkCwUccLCBViCSSPzE6TyRhyhMMWKKJTKmUq1Vq9Ua0LsHS6PXAVGwoxw+GgoAAQpBICg4GyxtBeEw7hxRk9Buz3qLvN8UmI-nJFCo1JpdPpnKZzE07Oi4QiPMj-KjYRijGScclRIwCRjiRjrcVSuUiVUdbSGtANHyBULsJ0JY9nrK+ABmRV2lUA9UgzXgnWQ-UW8LGpG+M2gIJpy3WxK21Lu8JOuEuikl0DUr11H2p-2CtlWHTB5hAA
π» Code
// Correctly infers type as string
const works: string[] = [...Array(5)]
.map(v => {
if (v %2 === 0) {
return 'a string';
}
return null;
})
.filter(v => !!v);
// Doesn't work for some reason even though its basically the same
const doesntWork1: string[] = [...Array(5)]
.map(v => {
if (v %2 === 0) {
return 'a string';
}
return null;
})
.filter(v => v);
// Cant infer Boolean working
const doesntWork2: string[] = [...Array(5)]
.map(v => {
if (v %2 === 0) {
return 'a string';
}
return null;
})
.filter(Boolean);
const doesntWork3: string[] = [...Array(5)]
.map(v => {
if (v %2 === 0) {
return 'a string';
}
return null;
})
.filter(v => Boolean(v));
π Actual behavior
See playground; it can't infer types properly.
π Expected behavior
All have the same type
Additional information about the issue
No response
π Search Terms
Inferred Type Predicates Boolean
π Version & Regression Information
This is a new issue introduced in 5.5
β― Playground Link
https://www.typescriptlang.org/play/?isolatedDeclarations=true#code/PTAEGEHsCdoUwMYBcA2BPUBLAdgMztAM6hJoAOcoAhsYUtDgOYBQCk2doA7jANaEAuUHQbZGAbQC6oALyhxAOiUBBWFTQAKAKwBKSc1CHQCgLZUyGgG6yAfKADeBo88y5QV0AFIATLJlyABh0HJ2cw0HgkAFdobFAAcipheiZ4gG5QsIBfZkznSJi47CiUFAznLJ1MhVxMFCQCDxk7AEIWyx0M5hBQABFIOEJseKRuPlBcGGFIE0p4GnZQOEs4OKQAC0goxnWsJGIAIxpMBCpSjA3KQipZ1nZOABMBoaQAdT4ARiERJilZeSUClU0HU2j01TMFmszRC4UMrnc1h8fkCwUccLCBViCSSPzE6TyRhyhMMWKKJTKmUq1Vq9Ua0LsHS6PXAVGwoxw+GgoAAQpBICg4GyxtBeEw7hxRk9Buz3qLvN8UmI-nJFCo1JpdPpnKZzE07Oi4QiPMj-KjYRijGScclRIwCRjiRjrcVSuUiVUdbSGtANHyBULsJ0JY9nrK+ABmRV2lUA9UgzXgnWQ-UW8LGpG+M2gIJpy3WxK21Lu8JOuEuikl0DUr11H2p-2CtlWHTB5hAA
π» Code
π Actual behavior
See playground; it can't infer types properly.
π Expected behavior
All have the same type
Additional information about the issue
No response