Skip to content

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

Open
Mateusz Burzyński (Andarist) wants to merge 2 commits into
microsoft:mainfrom
Andarist:fix/untyped-module-suggestion-after-emit
Open

Mateusz Burzyński (Andarist) wants to merge 2 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

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

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

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.

This branch has not been deployed

No deployments
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: Not started

Development

Successfully merging this pull request may close these issues.

2 participants