-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels