-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Proposal: Support switch/if type guards with destructuring #13403
Labels
Duplicate
An existing issue was already created
Comments
RyanCavanaugh
added
the
Needs Investigation
This issue needs a team member to investigate its status.
label
May 24, 2017
duplicate of #10976 |
mhegazy
added
Duplicate
An existing issue was already created
and removed
Needs Investigation
This issue needs a team member to investigate its status.
labels
Nov 9, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
For a lot of code duplication, its often helpful to destructure objects for later use. Type guards on switch/if help a lot in preventing unnecessary casts, but could be extended to infer a deeper understanding in some cases.
Lets use a trivial example:
In
doStuffDestructured
, we can logically infer that because we destructured vehicle at a moment in time, that the types/values are tied together, just as we indoStuff
.At a minimum I would propose this works for
const
destructuring as you can make reasonable assumptions outside of function scope:It seems to follow that for destructuring with
let
outside of scope means we cannot track if the values have been assigned to something else, but could technically supportlet
destructuring within scope. Honestly, I think its too hard to reasonable about for most end users that only supporting this forconst
is reasonable.Thanks
CC/ @andy-ms @ahejlsberg @mhegazy @RyanCavanaugh
The text was updated successfully, but these errors were encountered: