Skip to content

Conditional type simplified too earlyΒ #46761

Closed

Description

@webstrand

Bug Report

πŸ”Ž Search Terms

conditional tuple extend simplify type parameter constraint

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about conditional types

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Bit = 0 | 1;
type And<A extends Bit, B extends Bit> = [A, B] extends [1, 1] ? 1 : 0;

type Test<A extends Bit, B extends Bit> = And<A extends 1 ? 0 : 1, B extends 1 ? 0 : 1>;
//    ^? type Test<I1 extends Bit, I2 extends Bit> = 1

type a = Test<1, 1>; // 1, should be 0

πŸ™ Actual behavior

Test<A, B> is being incorrectly simplified to 1 before being called, and Test<1, 1> is resolving incorrectly to 1.

πŸ™‚ Expected behavior

Test<A, B> should not be simplified, and Test<1, 1> should resolve to 0.

Activity

  1. andrewbranch commented on Nov 10, 2021

    @andrewbranch
    Member

    Your inner conditional types being fed to And are distributive. Making them not distributive fixes it. Still, it feels odd to me. Wesley Wigham (@weswigham) is this expected behavior?

  2. webstrand commented on Nov 10, 2021

    @webstrand
    ContributorAuthor

    Some more weird behavior: If I extract the conditional out into an alias, Test1<A,B> still gets simplified to 1, but if I add another branch to that conditional, Test2<A,B> is not simplified: playground The latter should still be distributive, right?

  3. whzx5byb commented on Nov 10, 2021

    @whzx5byb

    If you make And like this, Test<A, B> will resolve to 0. That's weird.

    type And<A extends Bit, B extends Bit> = A extends 1 ? B extends 1 ? 1 : 0 : 0;
  4. added
    Needs Investigation
    on Nov 12, 2021
  5. added
    Fix Available
    on Dec 9, 2021
  6. added
    Rescheduled
    on May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Fix AvailableNeeds InvestigationRescheduled

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions