-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Type narrowing for Tuple-Elements #12849
Copy link
Copy link
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed