Skip to content

Stop alias deprecation walks at declaration-free targets - #65484

Open
Marc Rousavy (mrousavy) wants to merge 2 commits into
microsoft:mainfrom
mrousavy:fix/declaration-free-alias-deprecation
Open

Marc Rousavy (mrousavy) wants to merge 2 commits into
microsoft:mainfrom
mrousavy:fix/declaration-free-alias-deprecation

Conversation

@mrousavy

@mrousavy Marc Rousavy (mrousavy) commented Nov 13, 2026 •

Copy link
Copy Markdown

Fixes a checker hang when a function returns a namespace imported from a CommonJS module whose export is undefined:

// target.cjs
module.exports = undefined;
// bridge.mjs
import * as ns from "./target.cjs";
export function read() { return ns; }
// main.ts
import { read } from "./bridge.mjs";
read();

In resolveAliasWithDeprecationCheck, the immediate alias target here has no declarations (the intrinsic undefined symbol). That branch neither advances symbol nor breaks, so the loop never ends. The walk now only continues when the target has declarations and breaks otherwise.

The test is compiler/aliasToDeclarationFreeUndefined.ts. Without the fix it times out in resolveAliasWithDeprecationCheck. The existing jsdocDeprecated_suggestion* fourslash tests cover deprecation suggestions through re-exports and still pass.

go -C ./tsc test -count=1 -run TestLocal/aliasToDeclarationFreeUndefined ./internal/testrunner
go -C ./tsc test -count=1 -run 'TestJsdocDeprecated_suggestion|TestTypeReferenceAndImportDeprecated' ./internal/fourslash/tests

AI assistance was used to investigate and prepare this patch.

@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 13, 2026
@mrousavy

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@mrousavy
Marc Rousavy (mrousavy) marked this pull request as ready for review November 13, 2026 11:39
Copilot AI balanced review requested due to automatic review settings November 13, 2026 11:39
@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.

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.

🟢 Approval recommended

No active review issues are reported for the fix to the checker hang during CommonJS namespace resolution.

No open issues 🎉

What changed in this PR

Fixes a native TypeScript checker hang when resolving a namespace imported from a CommonJS module that exports undefined.

Changes:

  • Stops alias deprecation walks at declaration-free targets while preserving the resolved namespace.
  • Adds reduced, cyclic-import, and unused-namespace compiler fixtures with type and symbol baselines.
  • Adds a checker control test for declared-alias deprecation suggestions and TS2322 diagnostics.
File Description
tsc/​internal/​checker/​checker.go Terminates alias walks when the target has no declarations.
tsc/​internal/​checker/​alias_terminal_test.go Checks declared-alias deprecations and an assignment type error.
tsc/​testdata/​tests/​cases/​compiler/​aliasToDeclarationFreeUndefined.ts Adds the minimal hang regression.
tsc/​testdata/​tests/​cases/​compiler/​aliasToDeclarationFreeUndefinedCycle.ts Covers the original cyclic-import scenario.
tsc/​testdata/​tests/​cases/​compiler/​aliasToDeclarationFreeUndefinedUnused.ts Adds an unused-namespace control.
tsc/​testdata/​baselines/​reference/​compiler/​aliasToDeclarationFreeUndefined.types Records the reduced case’s namespace and return types.
tsc/​testdata/​baselines/​reference/​compiler/​aliasToDeclarationFreeUndefined.symbols Records symbol resolution for the reduced case.
tsc/​testdata/​baselines/​reference/​compiler/​aliasToDeclarationFreeUndefinedCycle.types Records inferred types across the import cycle.
tsc/​testdata/​baselines/​reference/​compiler/​aliasToDeclarationFreeUndefinedCycle.symbols Records symbol resolution across the import cycle.
tsc/​testdata/​baselines/​reference/​compiler/​aliasToDeclarationFreeUndefinedUnused.types Records types for the unused-namespace control.
tsc/​testdata/​baselines/​reference/​compiler/​aliasToDeclarationFreeUndefinedUnused.symbols Records symbols for the unused-namespace control.

Review effort: Balanced

Drop the Go unit test and the cycle and unused fixtures. The remaining
compiler test uses harness options instead of a tsconfig. Deprecation
walks through re-exports stay covered by jsdocDeprecated_suggestion*.

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

None yet

Development

Successfully merging this pull request may close these issues.

3 participants