Skip to content

Fix flaky diagnostic added by emit for typeof import() type qualifiers - #64636

Open
Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:fix-flaky-typeof-import-type-qualifier
Open

Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:fix-flaky-typeof-import-type-qualifier

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes the issue reported here: #64623 (comment)

Copilot AI balanced review requested due to automatic review settings October 5, 2026 10:26
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 5, 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.

for ast.IsPropertyAccessOrQualifiedName(topProp) {
if ast.IsPartOfTypeNode(topProp) {
// Names in an import type's qualifier (`ns.y` in `typeof import("./b").ns.y`) are exports of the imported module, not references to this file's imports
if ast.IsPartOfTypeNode(topProp) || isImportTypeQualifierPart(topProp) != nil {

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.

Per comment in isPartOfTypeNodeInParent:

// Do not recursively call isPartOfTypeNode on the parent. In the example:
//     let a: A.B.C;
// Calling isPartOfTypeNode would consider the qualified name A.B a type node.
// Only C and A.B.C are type nodes.

So, unfortunately, the import type qualifier parts have to be tested separately here.

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 checker change correctly distinguishes imported-module qualifiers and is covered by diagnostic and emit regressions.

Review effort: Balanced
Findings: None

What changed in this PR

Prevents emit-time alias tracking from misinterpreting typeof import() qualifiers as local imports, avoiding flaky diagnostics and incorrect import retention.

Changes:

  • Skip linked-reference marking for import-type qualifiers.
  • Add regression tests for diagnostics and import elision.
  • Add corresponding compiler baselines.
File Description
tsc/​internal/​checker/​checker.go Excludes import-type qualifiers from local alias tracking.
tsc/​testdata/​tests/​cases/​compiler/​noFlakyDiagnosticsTypeofImportTypeQualifier1.ts Tests unresolved-module diagnostics.
tsc/​testdata/​tests/​cases/​compiler/​noFlakyDiagnosticsTypeofImportTypeQualifier2.ts Tests missing exported qualifiers.
tsc/​testdata/​tests/​cases/​compiler/​importElisionTypeofImportTypeQualifier.ts Tests correct import elision.
tsc/​testdata/​baselines/​reference/​compiler/​noFlakyDiagnosticsTypeofImportTypeQualifier1.errors.txt Records expected diagnostics.
tsc/​testdata/​baselines/​reference/​compiler/​noFlakyDiagnosticsTypeofImportTypeQualifier1.js Records emitted JavaScript.
tsc/​testdata/​baselines/​reference/​compiler/​noFlakyDiagnosticsTypeofImportTypeQualifier1.symbols Records symbol resolution.
tsc/​testdata/​baselines/​reference/​compiler/​noFlakyDiagnosticsTypeofImportTypeQualifier1.types Records inferred types.
tsc/​testdata/​baselines/​reference/​compiler/​noFlakyDiagnosticsTypeofImportTypeQualifier2.errors.txt Records expected diagnostics.
tsc/​testdata/​baselines/​reference/​compiler/​noFlakyDiagnosticsTypeofImportTypeQualifier2.js Records emitted JavaScript.
tsc/​testdata/​baselines/​reference/​compiler/​noFlakyDiagnosticsTypeofImportTypeQualifier2.symbols Records symbol resolution.
tsc/​testdata/​baselines/​reference/​compiler/​noFlakyDiagnosticsTypeofImportTypeQualifier2.types Records inferred types.
tsc/​testdata/​baselines/​reference/​compiler/​importElisionTypeofImportTypeQualifier.js Confirms the import is elided.
tsc/​testdata/​baselines/​reference/​compiler/​importElisionTypeofImportTypeQualifier.symbols Confirms qualifier symbol resolution.
tsc/​testdata/​baselines/​reference/​compiler/​importElisionTypeofImportTypeQualifier.types Confirms resulting types.

💡 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