angus-c / angus-c/just

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

Offen
#584 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
6.2k
Forks
209
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

```TS
[PromiseRejectedResult | PromiseFulfilledResult, PromiseRejectedResult | PromiseFulfilledResult]
```

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

```TS
[ PromiseFulfilledResult, 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.