Skip to content

Conversation

@raimannma
Copy link

This PR fixes an issue where referencing unexported types indirectly (e.g., via Parameters<typeof fn>[1]) would fail during declaration emit.

The fix involves implementing tryReuseExistingTypeNodeHelper in the node builder. This allows the compiler to reuse the existing type node from the source code if the entity names within it are visible in the emitting scope, rather than attempting to synthesize a new type node from the resolved type (which would fail if the underlying type is unexported).

Fixes #2504

Copilot AI review requested due to automatic review settings January 15, 2026 12:49
@raimannma
Copy link
Author

@raimannma please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a declaration emit error (TS4023: "cannot be named") that occurred when using indirect type references to unexported types through utility types like Parameters<typeof fn>[1]. The fix implements the tryReuseExistingTypeNodeHelper function in the node builder to reuse existing type nodes from source code when all entity names within them are visible in the emitting scope, rather than attempting to synthesize new type nodes from resolved types (which would fail for unexported types).

Changes:

  • Implements tryReuseExistingTypeNodeHelper to validate and reuse existing type nodes with visibility checks
  • Adds new tracker methods (IsEntityNameVisible and TrackEntityName) to check entity name visibility
  • Replaces getOptionalType calls with addOptionalityEx to properly handle optionality with strict mode awareness
  • Adds a test case demonstrating the fix for the reported issue

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
testdata/tests/cases/conformance/parametersTypeResolutionWithUnexportedInterface.ts Test case verifying the fix for indirect references to unexported types via Parameters utility type
internal/nodebuilder/types.go Adds interface methods for entity name visibility checking
internal/checker/symboltracker.go Implements entity name visibility forwarding methods in checker's symbol tracker
internal/transformers/declarations/tracker.go Implements entity name visibility methods using resolver
internal/checker/nodebuilderimpl.go Implements tryReuseExistingTypeNodeHelper with validation/tracking logic and fixes optionality handling

@raimannma raimannma force-pushed the fix_allow_references_to_unexported_types branch from 0086996 to 5b33c0f Compare January 15, 2026 13:37
@jakebailey
Copy link
Member

I would think this conflicts with #1693 / #2459

@raimannma raimannma force-pushed the fix_allow_references_to_unexported_types branch from 0965aa2 to b22d9d5 Compare January 18, 2026 09:59
@raimannma raimannma closed this Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TS4023 "cannot be named" - tsgo not allowing references to unexported types

2 participants