fix: error on private property access in generic intersection types#4290
Closed
hesam-oxe wants to merge 2 commits into
Closed
fix: error on private property access in generic intersection types#4290hesam-oxe wants to merge 2 commits into
hesam-oxe wants to merge 2 commits into
Conversation
Added check for conflicting private properties when resolving indexed access on intersection types. Closes microsoft/TypeScript#62294
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a diagnostic guard to prevent indexed-access type queries from succeeding on intersection types that contain conflicting private properties.
Changes:
- Detects intersection types with conflicting private properties during indexed access type computation.
- Emits
Property_0_is_private_and_only_accessible_within_class_1when an indexed access targets such a property. - Aborts the indexed access type resolution by returning
nilin that scenario.
Comments suppressed due to low confidence (2)
internal/checker/checker.go:1
- The new guard only triggers when
accessNode != nil, which means the checker may still compute and return an indexed-access type for an intersection containing a conflicting private property whenaccessNodeis nil. That contradicts the comment ('we shouldn't be able to access those properties') and can lead to inconsistent behavior depending on call site. Consider separating the concerns: always prevent the access (e.g., returnnilor an appropriate failure type) whenisConflictingPrivateProperty(prop)is true, and conditionally emit the diagnostic only whenaccessNode != nil.
internal/checker/checker.go:1 - There is trailing whitespace after the comma at the end of the
c.error(...,line. This will typically fail whitespace-focused linters and is easy to fix by removing the trailing space (and/or lettinggofmtformat the call).
Member
|
This unconditionally errors if you try to use an indexed access type on an intersection of two classes with conflicting private members, which is not correct. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When two classes have conflicting private properties, accessing them
via indexed access on their intersection should report an error,
consistent with union behavior.
This is the Go implementation of the fix originally submitted to
microsoft/TypeScript#63548 (closed — JS codebase is winding down).
Root Cause
getIndexedAccessTypeOrUndefineddid not check for conflictingprivate properties in intersection types before resolving indexed access.
Fix
Added check after
getReducedType()to detect conflicting privateproperties and report
Property_0_is_private_and_only_accessible_within_class_1.Before
After
Related
Closes microsoft/TypeScript#62294