Skip to content

Distributive conditional types can't distribute over NoInfer types wrapping a unionΒ #61076

Open

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

Activity

  1. added
    Possible Improvement
    on Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Conditional TypesPossible Improvement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions