Skip to content

Ignore source files / module declarations in couldContainTypeVariables - #65481

Open
Jake Bailey (jakebailey) wants to merge 2 commits into
microsoft:mainfrom
jakebailey:synthetic-default-import-type-variables
Open

Jake Bailey (jakebailey) wants to merge 2 commits into
microsoft:mainfrom
jakebailey:synthetic-default-import-type-variables

Conversation

@jakebailey

Copy link
Copy Markdown
Member

Fixes #65445

This traces back to microsoft/typescript-go#4687. That PR gave a synthetic module wrapper symbol a declaration so it could be sorted, but then that made couldContainTypeVariables walk into it when it shouldn't. Strada didn't give that symbol a declaration so it didn't either.

Fix it by skipping decls that are source files / module declarations.

The object type wrapping a module for a synthetic default import has
the module's declarations, so that types are ordered the same way
wherever it is compared. Having declarations made it an anonymous type
that could reference type parameters, so inference explored its
members. For import("cloudflare:workers").then(mod => mod), inferring
from the callback erased the type parameter of a generic function the
module exports, and instantiating its return type with any never
ended, reporting TS5115. A module is never within the scope of a type
parameter, so the wrapper is again known not to contain any.

Fixes 65445

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 were identified for the dynamic-import inference fix.

No open issues 🎉

What changed in this PR

Addresses #65445, a TS5115 regression during dynamic-import callback inference, by preventing the native compiler from exploring synthetic module wrappers that cannot reference type parameters.

Changes:

  • Exclude wrappers backed by source-file or module declarations from couldContainTypeVariables.
  • Add a regression test combining dynamic import, callback inference, and recursive conditional types.
  • Add expected type and symbol baselines.
File Description
tsc/​testdata/​tests/​cases/​compiler/​syntheticDefaultImportTypeInference.ts Adds the focused dynamic-import inference regression test.
tsc/​testdata/​baselines/​reference/​compiler/​syntheticDefaultImportTypeInference.types Records expected inferred types, including Promise<number>.
tsc/​testdata/​baselines/​reference/​compiler/​syntheticDefaultImportTypeInference.symbols Records expected symbol bindings for the regression test.
tsc/​internal/​checker/​checker.go Identifies module wrappers and excludes them from type-variable traversal.

Review effort: Balanced

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

Author: Team 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.

7.1 regression: TS5115 for import("cloudflare:workers") with @cloudflare/workers-types

2 participants