Skip to content

Fix flaky diagnostic added by declaration emit for untyped module imports - #64479

Merged
Jake Bailey (jakebailey) merged 6 commits into
microsoft:mainfrom
Andarist:fix/untyped-module-suggestion-after-emit
Sep 29, 2026
Merged

Jake Bailey (jakebailey) merged 6 commits into
microsoft:mainfrom
Andarist:fix/untyped-module-suggestion-after-emit

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes crash reported here: #64458 (comment)

Fourslash now initializes the server with trackFlakyDiagnostics set to panic, so every
textDocument/diagnostic request also emits the program and fails if the diagnostics differ
before and after emit. This complements the compiler harness's pre/post-emit check, which
compares separate programs by diagnostic count only and doesn't catch emit adding a
diagnostic to an already-checked program.

Add fourslash tests where declaration emit adds a "Could not find a declaration file for
module" (7016) suggestion for an untyped import whose error was dropped by checking
(plain JS file, @ts-expect-error, and an ES module under NodeNext).
…FromDeclaration

getExternalModuleFileFromDeclaration is only used by emit (IsImportRequiredByAugmentation,
module transforms) and by type-node reuse in the node builder. It resolved with the
specifier as the error node, so for an untyped JS module it re-ran errorOnImplicitAnyModule
with moduleNotFoundError == nil and recorded 7016 as a *suggestion*. Checking had already
reported 7016 as an error, which was then dropped (plain JS file or @ts-expect-error), but
suggestions bypass both filters, so the diagnostic appeared only after emit and tripped
the LSP's flaky-diagnostic tracking.

Resolve with ignoreErrors so these emit-time queries are free of diagnostic side effects.

Fixes microsoft#64458
Copilot AI balanced review requested due to automatic review settings September 27, 2026 10:29
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 27, 2026
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 27, 2026
@typescript-automation

Copy link
Copy Markdown
Contributor

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Comment thread tsc/internal/fourslash/fourslash.go Outdated
CodeLensShowLocationsCommandName: new(showCodeLensLocationsCommandName),
// Make every textDocument/diagnostic request also emit the program and fail if the
// diagnostics differ before and after emit, e.g. because the emit resolver added some.
TrackFlakyDiagnostics: new(lsproto.DiagnosticFlakeLogLevelPanic),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this "builds up" on microsoft/typescript-go#4526 and microsoft/typescript-go#4710 . It feels the same unconditional flaky diagnostic tracking can just be added to fourslash. And it makes it easier to write tests for this without going full in on server-level tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel wary of this a bit... Wesley Wigham (@weswigham)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hrm. compiler tests do do this check by default - but I guess the question is mostly just why these tests needs to be fourslash instead of compiler? Like, it's probably fine enough to turn on like this, I'm just surprised these tests aren't testable in the compiler harness, since it seems like they're just getting diagnostics? Fourslash tests are also a bit more sensitive to operation sequencing, so for fourslash it really should be opt-in - as some tests need specific server operation sequences to test the regressions they're looking for.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good shout. I couldnt reproduce this in the compiler tests initially - this relies on @captureSuggestions. But even with that, it didn't quite work (I tried that initially and gave up). To actually make it work the suggestion diagnostics had to be captured before emitting the declarations. I think this is a proper change regardless of the core fix here and made that change in:
dae525b

That finally reproduced the issue in compiler tests. But I've still kept TrackFlakyDiagnostics as a fourslash option in:
15553ab

And in the final version I dropped the fourslash tests for this completely as they were just replaced by the compiler tests.

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.

Copilot review overview

🟢 Approval recommended

The focused fix prevents emit-only diagnostic mutation and is covered across the reported import scenarios.

Review effort: Balanced
Findings: None

What changed in this PR

Prevents declaration emit/type printing from introducing diagnostics after checking.

Changes:

  • Resolves emit-time module references without reporting errors.
  • Enables flaky-diagnostic detection across Fourslash tests.
  • Adds regression coverage for package, JavaScript, and NodeNext imports.
File Description
tsc/​internal/​checker/​checker.go Suppresses diagnostic side effects during emit-time resolution.
tsc/​internal/​fourslash/​fourslash.go Enables panic-level flaky-diagnostic tracking.
tsc/​internal/​fourslash/​tests/​noFlakyDiagnosticsUntypedModule1_test.go Tests an untyped package import.
tsc/​internal/​fourslash/​tests/​noFlakyDiagnosticsUntypedModule2_test.go Tests a relative JavaScript import.
tsc/​internal/​fourslash/​tests/​noFlakyDiagnosticsUntypedModule3_test.go Tests a NodeNext .mjs import.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Sep 29, 2026
Merged via the queue into microsoft:main with commit 299a555 Sep 29, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants