Skip to content

Type narrowing for Tuple-Elements #12849

@christyharagan

Description

@christyharagan

TypeScript Version: nightly (2.2.0-dev.20161210)

Code

function test([a, b]: [number, number] | [string, string]) {
  if (typeof a === 'number') {
    b++
  }
}

Expected behavior:
b to be narrowed to number and the resulting code to throw no compiler errors

Actual behavior:
b has type number | string and thus the code throws a compiler error complaining that b++ can only apply to numbers

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions