microsoft / microsoft/TypeScript

Distributive conditional types can't distribute over `NoInfer` types wrapping a union

Open
#61,076 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Conditional Types Help Wanted Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔎 Search Terms

noinfer union distributive conditional distribution

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.0-dev.20250129&ssl=10&ssc=8&pln=1&pc=1#code/C4TwDgpgBAYg9nAogNwgO2FAvFA3lUSALigCIYB5C0qAXwG4AoQ6AIQEMAnFdTHfFiVKsAggCUaDRs3DQAkmjABXPrAQ8MUAD5QO3VBiYzIUMRADOSgDarEAD2Cd2AY2AAeBcuAAaNUgPAAHxMAPQhUBEAegD80iymFtbAAEzYUPaOLu4AcnAKAGYQnB6KKoG+8P68wYxhEVAxjEA

💻 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground repro and compare how Extract distributes over Input versus NoInfer. Trace the compiler's conditional-type distribution and NoInfer handling; done means Result2 resolves to { type: "FOO"; } instead of never, with coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.