You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I feel that the parens should not be required. The JSDoc cast should have the lowest precedence and apply to the entire expression on the right hand side
The text was updated successfully, but these errors were encountered:
this is the intended design. looking up these cast expressions in comments is not cheep. moreover, scoping rules are not clear either.
we made a design choice to only look them up for parenthesized expressions.
The bigger issue, I think, is that we'd need to start parsing and maintaining JSDoc ASTs on all expressions - and we're very frugal about where we do that right now. The actual lookup is fairly cheap - no moreso than a normal TS-style cast, really (only a slightly more complicated AST to traverse to find the type to cast to).
Ok, if there is a technical reason why the parens necessary, feel free to close this out. I only opened this because when I first tried to write a jsdoc cast I forgot the parens around the expression, and it took me a moment to realize this
From #5158
TypeScript Version: 2.5.2
Code
For the JavaScript:
Expected behavior:
The type of
img
isHTMLImageElement
Actual behavior:
The type of
img
isany
. You currently need parens around the expression for this to work properly:I feel that the parens should not be required. The JSDoc cast should have the lowest precedence and apply to the entire expression on the right hand side
The text was updated successfully, but these errors were encountered: