Closed
Description
π Search Terms
Inferred Type Predicates Boolean
π Version & Regression Information
This is a new issue introduced in 5.5
β― Playground Link
π» 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
Metadata
Metadata
Assignees
Labels
No labels