Fixed control flow Analysis of aliased discriminants with parenthesized initializers#61788
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where discriminant properties aliased through parenthesized or destructured initializers weren't correctly recognized in control-flow analysis.
- Added comprehensive tests covering both direct and parenthesized/destructured alias patterns.
- Refactored the alias resolution logic in the type checker to use a helper that skips parentheses.
- Introduced
getCandidateVariableDeclarationInitializerto centralize initializer extraction.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/cases/conformance/controlFlow/controlFlowAliasing2.ts | New tests for aliased discriminants with various initializer forms |
| tests/baselines/reference/controlFlowAliasing2.symbols | Baseline update for the new conformance tests |
| src/compiler/checker.ts | Extracted initializer logic into a helper and updated alias-matching branches |
Comments suppressed due to low confidence (1)
src/compiler/checker.ts:29266
- [nitpick] Consider renaming this helper to something shorter like
getInitializerSkippingParensorextractInitializerfor improved readability.
function getCandidateVariableDeclarationInitializer(node: Node) {
|
Any chance for this passing? |
|
@typescript-bot test it |
|
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
|
@jakebailey Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
|
Is there a chance for it landing anytime soon? |
|
Anything new here? |
|
At the very least, a merge from main (and a review of course). |
|
I synced it with main - so now it's only missing a review :) |
fixes #61784