[WIP] Fix regression in 6.0: Broader type inference issue#63310
[WIP] Fix regression in 6.0: Broader type inference issue#63310
Conversation
Agent-Logs-Url: https://github.com/microsoft/TypeScript/sessions/c865d3f5-aaf0-4dfc-8051-47e4fe1b3e86 Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/TypeScript/sessions/c865d3f5-aaf0-4dfc-8051-47e4fe1b3e86 Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
| return ContainerFlags.IsControlFlowContainer; | ||
|
|
||
| case SyntaxKind.PropertyDeclaration: | ||
| return (node as PropertyDeclaration).initializer ? ContainerFlags.IsControlFlowContainer : ContainerFlags.None; |
There was a problem hiding this comment.
It would be worth rechecking if this now shouldn't include PropagatesThisKeyword too
|
@typescript-bot test it |
|
Hey @RyanCavanaugh, the results of running the DT tests are ready. Everything looks the same! |
|
@RyanCavanaugh Here are the results of running the user tests with tsc comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
There was a problem hiding this comment.
Pull request overview
Fixes a TypeScript 6.0 regression where module-level narrowing from a broader-typed const could leak into class property initializer inference, by restoring an isolated control-flow scope for property initializers in the binder.
Changes:
- Restore
SyntaxKind.PropertyDeclarationas a control-flow container (when it has an initializer) ingetContainerFlags. - Add a compiler regression test ensuring class/static properties infer the declared wider type (
AB) rather than a narrowed literal. - Add new baselines (
.types,.symbols,.js) for the regression test.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/compiler/binder.ts | Restores property declarations with initializers as isolated control-flow containers to prevent narrowing leakage into inference. |
| tests/cases/compiler/classPropertyInferenceFromBroaderTypeConst.ts | New regression test covering instance and static class property inference from a broader-typed const. |
| tests/baselines/reference/classPropertyInferenceFromBroaderTypeConst.types | Baseline verifying inferred types (e.g., D: AB, SD: AB) and switch narrowing behavior. |
| tests/baselines/reference/classPropertyInferenceFromBroaderTypeConst.symbols | Baseline verifying symbol binding for the new test. |
| tests/baselines/reference/classPropertyInferenceFromBroaderTypeConst.js | Baseline verifying emit output for the new test. |
| case SyntaxKind.PropertyDeclaration: | ||
| return (node as PropertyDeclaration).initializer ? ContainerFlags.IsControlFlowContainer : ContainerFlags.None; | ||
|
|
There was a problem hiding this comment.
PR description indicates the full test suite hasn’t been run yet. Please run the repo’s required verification (at least npx hereby runtests-parallel, plus npx hereby lint and npx hereby format if applicable) and update the PR before this is merged, since binder control-flow container changes can have broad impact.
|
@RyanCavanaugh Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
|
@RyanCavanaugh Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PropertyDeclarationfromContainerFlags.IsControlFlowContainerin binder.tsconst DEFAULT: AB = 'A'→"A") to leak into class property type inferencePropertyDeclarationasIsControlFlowContainerinbinder.tsclassPropertyInferenceFromBroaderTypeConst.tsD: AB,this.D: AB)🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.