ts reset for `.filter` is not working in all cases
xiduzo opened this issue · 1 comments
xiduzo commented
I am not sure if any of this would even be possible.
Given the following array
const myArray = [1, undefined, 10, undefined, undefined, 0]
// ^? (number | undefined)[]
I can do the following filter using Boolean
const myFilteredArray = myArray.filter(Boolean)
// ^? number[]
But when filtering using any other method it does not give back the correct type
const myFilteredArray = myArray.filter(Number.isNaN)
// ^? (number | undefined)[]
// Below might be impossible, but would be sick if ts can do this
function myCustomFilter(input?: number) {
return input !== undefined
}
const myFilteredArray = myArray.filter(myCustomFilter)
// ^? (number | undefined)[]
mattpocock commented
This will be fixed upstream in TS 5.5