Skip to content

fix: error on private property access in generic intersection types#4290

Closed
hesam-oxe wants to merge 2 commits into
microsoft:mainfrom
hesam-oxe:fix/private-intersection-error-go
Closed

fix: error on private property access in generic intersection types#4290
hesam-oxe wants to merge 2 commits into
microsoft:mainfrom
hesam-oxe:fix/private-intersection-error-go

Conversation

@hesam-oxe

Copy link
Copy Markdown

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

getIndexedAccessTypeOrUndefined did not check for conflicting
private properties in intersection types before resolving indexed access.

Fix

Added check after getReducedType() to detect conflicting private
properties and report
Property_0_is_private_and_only_accessible_within_class_1.

Before

type Z<T extends A & B> = T["a"];         // no error ❌
type Z3<T extends A, T2 extends B> = (T & T2)["a"];  // no error ❌

After

type Z<T extends A & B> = T["a"];         // Error ✅
type Z3<T extends A, T2 extends B> = (T & T2)["a"];  // Error ✅

Related

Closes microsoft/TypeScript#62294

Added check for conflicting private properties when resolving indexed access on intersection types. Closes microsoft/TypeScript#62294
Copilot AI review requested due to automatic review settings June 12, 2026 06:41

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.

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_1 when an indexed access targets such a property.
  • Aborts the indexed access type resolution by returning nil in 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 when accessNode is 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., return nil or an appropriate failure type) when isConflictingPrivateProperty(prop) is true, and conditionally emit the diagnostic only when accessNode != 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 letting gofmt format the call).

@RyanCavanaugh

Copy link
Copy Markdown
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.

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.

Missing error about inability to access conflicting private properties on generic types involving intersections

3 participants