-
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
typeof Foo['bar'] has strange precedence #19707
Comments
It should have the same precedence as in an expression. but this is a breaking change, and so far there is no functional impact of this on the output. marking it as a revisit for now. |
Seems too late to change this now. |
Worth reconsidering in my opinion #44857 I kind of doubt anyone would be broken by this change. |
I remember discovering this a while back and was quite surprised that the relative precedence for Worth noting though that I’ve seen a lot of examples given out on Gitter and Discord that freely do stuff like |
Seems easy enough to make this change and compile tonnes of code to see what the rates of breaks is. |
TypeQuery is parsed as TypeScript/src/compiler/parser.ts Lines 3078 to 3081 in ef9fd97
@DanielRosenwasser Do we need to parse it as an expression? /cc @RyanCavanaugh |
Type queries combined with indexed access types currently produce a parse tree that is surprising in its behavior.
One would think that
typeof Foo['bar']
would be parsed astypeof (Foo['bar'])
, which would really be something liketypeof Foo.bar
.That's not the case. It's actually parsed as
(typeof Foo)['bar']
.Conveniently, it seems that semantically (when type-checking) these are identical, but it seems strange for syntactic consumers. Do we believe this is currently working as intended?
The text was updated successfully, but these errors were encountered: