-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Optional chaining: (a?.b).c is parsed as a?.b.c #1139
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
Labels
bug
Something isn't working
has pr
there is a PR raised to close this
package: typescript-estree
Issues related to @typescript-eslint/typescript-estree
Comments
4 tasks
I don't understand why babel handles this case differently. It seems to me like this is semantically no different. |
TS compiles
|
Hmmm yes, I am mistaken - it does change the order of execution and thus the return values and types. type T = Record<string, Record<string, string>>;
declare const x: T | undefined;
const v1 = x?.a.b;
const v2 = (x?.a).b;
// ^^^^^^ Object is possibly 'undefined'.
const v3 = (x?.a)?.b; |
Yep, it's tricky. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
bug
Something isn't working
has pr
there is a PR raised to close this
package: typescript-estree
Issues related to @typescript-eslint/typescript-estree
prettier/prettier#6657 is blocked by this issue.
What code were you trying to parse?
What did you expect to happen?
The outer node should be of type
MemberExpresion
, notOptionalMemberExpression
.What actually happened?
Both member expressions are
OptionalMemberExpression
as if the parens weren't there (a?.b.c
).Versions
@typescript-eslint/typescript-estree
2.5.1-alpha.3
TypeScript
3.7.0-rc
node
10.15.0
npm
6.11.3
The text was updated successfully, but these errors were encountered: