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

Typescript type for just-partition does not narrow type correctly when using a type guard #584

Open
vidhill opened this issue Sep 3, 2024 · 1 comment · May be fixed by #585
Open

Typescript type for just-partition does not narrow type correctly when using a type guard #584

vidhill opened this issue Sep 3, 2024 · 1 comment · May be fixed by #585

Comments

@vidhill
Copy link
Contributor

vidhill commented Sep 3, 2024

The Typescript type for just-partition does not narrow type correctly when using a type guard

I'm not sure what the best way to report/describe TS issues, so I will use screenshots,
I hope that that is okay,

In contrast with how using Array.filter() correctly narrows the type

The type returned from partition, when using the example type guard, is a tuple of unions of the possible values

[PromiseRejectedResult | PromiseFulfilledResult<boolean>, PromiseRejectedResult | PromiseFulfilledResult<boolean>]
Screenshot 2024-09-03 at 19 47 38

What I would really like/expect is that the types would be correctly inferred, in the same way that Array.filter() does

[ PromiseFulfilledResult<boolean>, PromiseRejectedResult ]

I can work around this by casting the result, but that is not ideal

Screenshot 2024-09-03 at 19 50 50

I have a suggested fix, using a function Type override

I will open a PR,

I just wanted to link the PR to an issue

@vidhill
Copy link
Contributor Author

vidhill commented Sep 4, 2024

- I edited above for (hopefully) more clarity

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