fix: allow references to unexported types#2514
fix: allow references to unexported types#2514raimannma wants to merge 3 commits intomicrosoft:mainfrom
Conversation
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
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
tryReuseExistingTypeNodeHelperto validate and reuse existing type nodes with visibility checks - Adds new tracker methods (
IsEntityNameVisibleandTrackEntityName) to check entity name visibility - Replaces
getOptionalTypecalls withaddOptionalityExto 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 |
0086996 to
5b33c0f
Compare
0965aa2 to
b22d9d5
Compare
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
tryReuseExistingTypeNodeHelperin 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