Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts reset for .filter is not working in all cases #197

Closed
xiduzo opened this issue May 26, 2024 · 1 comment
Closed

ts reset for .filter is not working in all cases #197

xiduzo opened this issue May 26, 2024 · 1 comment

Comments

@xiduzo
Copy link

xiduzo commented May 26, 2024

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
Copy link
Collaborator

This will be fixed upstream in TS 5.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants