Add a regression test for discriminating property access in parenthesized expression#51778
Conversation
| // extra parens on purpose | ||
| if (typeof (a.error) === 'undefined') { | ||
| a.result.prop; // number | ||
| } |
There was a problem hiding this comment.
This was reporting an error before this PR: #51720
The issue was that typeOfExpr.expression was passed to getDiscriminantPropertyAccess here:
https://github.com/microsoft/TypeScript/pull/50344/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8R25331
and it got fixed by @ahejlsberg since he changed this and now target is passed there:
https://github.com/microsoft/TypeScript/pull/51720/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8R26520
This works since target is the result of getReferenceCandidate:
https://github.com/microsoft/TypeScript/pull/50344/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8R25329
and that includes "skip parenthesis"-like logic:
https://github.dev/microsoft/TypeScript/blob/c124d0e2604bac1a428c24b98a1dd6508d860812/src/compiler/checker.ts#L25182-L25185
There was a problem hiding this comment.
#51720 has a test with optional chaining and parenthesis - that has worked before your PR despite the fact that the version without parenthesis reported an error. This test is kinda about the opposite situation (no optional chaining and parenthesis) - the version without parenthesis worked alright while the version with them reported an error.
I've concluded that they are slightly different and thus I've created a PR (I already had it locally as I was looking into fixing #51700 when you picked it up). I understand that they can be seen as similar enough though. Feel free to merge or close - whatever you think is best here.
|
@ahejlsberg It sounded like you were leaning against adding this test case. Does @Andarist 's explanation change that? If not, let's close it. |
…-parent-discriminate-union-narrowing # Conflicts: # tests/baselines/reference/narrowingTypeofUndefined.symbols # tests/baselines/reference/narrowingTypeofUndefined1.js
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
No description provided.