Skip to content

3.4.1 regression in distributed types #31121

Open
@aleclarson

Description

@aleclarson

TypeScript Version: 3.5.0-dev.20190425

The example below was taken from a real world use-case and simplified.

The U type is distributed while the T type remains the original union.

The T type is wrapped with Box<T> when U is not an object.

type Box<T> = { value: T }
type Test<T> = [T] extends [infer U]
  ? U extends object
    ? U
    : U | Box<T>
  : never

type A = number | { foo: number }
type B = Test<A>

In theory, the B type should be identical to:

type B = number | { foo: number } | Box<number | { foo: number }>

But in the latest version, the B type is instead identical to:

type B = number | { foo: number } | Box<number | (number & { foo: number })>

This works correctly in 3.3.x but not 3.4.x and later.

Playground Link: click here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Conditional TypesThe issue relates to conditional typesNeeds InvestigationThis issue needs a team member to investigate its status.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions