Skip to content

Fix watch diagnostics when global declaration is removed - #4848

Merged
John Favret (johnfav03) merged 2 commits into
microsoft:mainfrom
johnfav03:fix-issue-4838
Aug 10, 2026
Merged

Fix watch diagnostics when global declaration is removed#4848
John Favret (johnfav03) merged 2 commits into
microsoft:mainfrom
johnfav03:fix-issue-4838

Conversation

@johnfav03

Copy link
Copy Markdown
Contributor

Fixes #4838

When a script file stopped affecting the global scope, the incremental affected-files calculation used its new affectsGlobalScope value. If a global declaration was commented out or removed, the file no longer affected global scope, so only that file was rechecked. This meant that other files using that variable would retain stale semantic diagnostics and that watch mode would fail to report an error.

Copilot AI balanced review requested due to automatic review settings August 7, 2026 20:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes stale watch diagnostics when a changed script stops contributing to the global scope.

Changes:

  • Detects loss of global-scope impact and marks all relevant files changed.
  • Adds watch-mode regression coverage for removing and restoring a global declaration.
  • Adds the expected watch baseline.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/execute/incremental/programtosnapshot.go Invalidates files after global-scope loss.
internal/execute/tsctests/tscwatch_test.go Adds the watch regression scenario.
testdata/baselines/reference/tscWatch/commandLineWatch/watch-detects-error-across-global-script-files-when-global-decl-removed.js Records expected diagnostics and rebuilds.

@jakebailey

Copy link
Copy Markdown
Member

If it's not too much to ask, do you mind splitting this PR into two commits, where you add the test and baseline into the first commit, then the second commit is the fix with the baseline update that shows that it worked? Hard to tell for sure just from a one commit.

@johnfav03

Copy link
Copy Markdown
Contributor Author

Just split the test and the fix into two commits; with just the test, a clean build should report TS2304: Cannot find name 'a' whereas the incremental watch incorrectly reports 0 errors.

@johnfav03
John Favret (johnfav03) added this pull request to the merge queue Aug 10, 2026
Merged via the queue into microsoft:main with commit 1f55045 Aug 10, 2026
21 checks passed
@johnfav03
John Favret (johnfav03) deleted the fix-issue-4838 branch August 10, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsc --watch can't handle errors across files

3 participants