Microsoft/TypeScript

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

Open

#61,076 建立於 2025年1月29日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
Domain: Conditional TypesHelp WantedPossible Improvement

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

🔎 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

貢獻者指南