Skip to content

Nested generic object of unions is not assignable to equivalent union of nested generic objectsΒ #51318

@sluukkonen

Description

@sluukkonen

Bug Report

πŸ”Ž Search Terms

union, generic, nested, nested, complex

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried. I read through the FAQ and couldn't find relevant sections.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Test<T> = {
    test: T
}

declare let outer: Test<Test<"a">> | Test<Test<"b">>
declare let inner: Test<Test<"a" | "b">>

inner = outer // this is accepted
outer = inner // this is not

πŸ™ Actual behavior

The assignment outer = inner fails following error

Type 'Test<Test<"a" | "b">>' is not assignable to type 'Test<Test<"a">> | Test<Test<"b">>'.
  Type 'Test<Test<"a" | "b">>' is not assignable to type 'Test<Test<"a">>'.
    Type 'Test<"a" | "b">' is not assignable to type 'Test<"a">'.
      Type '"a" | "b"' is not assignable to type '"a"'.
        Type '"b"' is not assignable to type '"a"'.(2322)

πŸ™‚ Expected behavior

As far as I can tell, it should be accepted, but the type checker isn't quite smart enough. This issue came up in a larger real world example, but this was the minimal reproduction I could think of.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions