Skip to content

Nested conditional type with generic tuple argument always expands to false branch. #30708

Open
@Veetaha

Description

@Veetaha

TypeScript Version: next (3.4.0-dev.20190330), latest (3.4.1)

Search Terms:

  • tuple conditional type
  • tuple compare
  • tuple comparison

Code

type Not<T extends boolean> = [T] extends [true] ? false : true;
type NoOp<T extends boolean> = Not<Not<T>>; // always expands true (see intellisense)

type t0 = Not<Not<false>>; // false
type t1 = NoOp<false>;     // true (but should be false)

Expected behavior:
Type t1 must be false and NoOp must be of the nested conditional type that depends on T, but not of simple true unit type.
Actual behavior:
As you see, something is broken when you use generic argument for tuple comparison in conditional type, because when you expand your types manually (t0 is an expanded representation of t1) it works as expected.

Playground Link:

Klick me

Related Issues:

This bug report originated from my stackoverflow question.

Additional credits to @dragomirtitian and @fictitious for helping and localizing the bug to a minimal representation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions