Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type narrowing for Tuple-Elements #12849

Closed
christyharagan opened this issue Dec 12, 2016 · 4 comments
Closed

Type narrowing for Tuple-Elements #12849

christyharagan opened this issue Dec 12, 2016 · 4 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@christyharagan
Copy link

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

@RyanCavanaugh RyanCavanaugh added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Dec 12, 2016
@mhegazy
Copy link
Contributor

mhegazy commented May 5, 2017

Same underlying issue as #14957

@christyharagan
Copy link
Author

Should I close this in favour of #14957 ?

@mhegazy
Copy link
Contributor

mhegazy commented May 8, 2017

I would leave them both open. though both would be addressed by the same change, ppl tend to think of them as two separate scenarios. this way we have a landing point for users searching for similar issues.

@RyanCavanaugh RyanCavanaugh added Design Limitation Constraints of the existing architecture prevent this from being fixed and removed In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jul 22, 2020
@RyanCavanaugh
Copy link
Member

This would work if it weren't for the destructuring. Our CFA algorithm isn't able to correlate values from different places like this; this comes up from time to time but doesn't seem to merit the required work at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

3 participants