Skip to content

How should empty arrays and union types work together in 1.6? #4499

Closed
@osdm

Description

@osdm
var p = new Array<string>();
var q = true ? p : [];
q[0]

My reasoning follows, please correct me if I'm wrong.
According to 1.5 spec, type of q[0] was calculated in the following way:

  1. Take union type of Array<string> and empty array (Array<Undefined>).
  2. Reduce that union type, which gives us Array<string>, because string is a supertype of undefined.
  3. Widen that type (changes nothing).
  4. Type of q[0] is string.

According to 1.6 spec, type of q[0] should be calculated in the following way:

  1. Take union type of Array<string> and empty array (Array<Undefined>).
  2. No reduce is happening.
  3. Widen that type, resulting in (Array<string> | Array<any>).
  4. Type of q[0] is (string | any).

But that would break "no implicit any". Where did I make a mistake?

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions