-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Narrow type after assertion? #20682
Comments
Same as #8655? |
@RyanCavanaugh Looks like the same desired behavior for a different use case (using an |
Oh, actually, I just saw that #10485 "Treat if ("radius" in shape && shape.radius) {
shape.radius // Ok?
} |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.7.0-dev.201xxxxx
Would it be possible to treat an assertion like a type-guard and narrow the type within blocks that are "guarded" by an assertion?
For example:
Code
But you could consider the
(shape as Circle).radius
like the user saying:I realize that checking for a property is not considered good enough to narrow the type, but if the user has explicitly asserted the type it would be convenient if control flow could keep track of that in downstream code.
The text was updated successfully, but these errors were encountered: