Microsoft/TypeScript
Voir sur GitHubDistributive conditional types can't distribute over `NoInfer` types wrapping a union
Open
#61 076 ouverte le 29 janv. 2025
Domain: Conditional TypesHelp WantedPossible Improvement
Métriques du dépôt
- Stars
- (48 455 stars)
- Métriques de merge PR
- (Merge moyen 6j 17h) (9 PRs mergées en 30 j)
Description
🔎 Search Terms
noinfer union distributive conditional distribution
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type FooEvent = { type: "FOO" };
type BarEvent = { type: "BAR" };
type Input = FooEvent | BarEvent;
type Result = Extract<Input, FooEvent>;
// ^? type Result = { type: "FOO"; }
type Result2 = Extract<NoInfer<Input>, FooEvent>;
// ^? type Result2 = never
🙁 Actual behavior
Result2 gets computed as never
🙂 Expected behavior
Result2 should get computed as { type: "FOO"; }
Additional information about the issue
This is repro for the core problem behind this incorrect behavior: TS playground