You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[7.0] Can't access field if it is protected in one constituent of an intersection (type order dependent)ย #63749
declareclassDummy{a: number;// Remove this error in the guard goes away}typePublic=Base|Dummy;declareclassBase{protectedgetcontent(): string;protectedsetcontent(value: string);// Remove just this setter all errors go away}declareclassMock{getcontent(): string;setcontent(value: string);// Remove just this setter this all errors go away}declareconstw: Publicif(winstanceofMock){w.content;// Error in TS 7 }declareconstw2: Mock&Publicw2.contentdeclareconstw3: Public&Mockw3.content// Error in TS 7
๐ Actual behavior
The marked lines fail to type check with:
error TS2445: Property 'content' is protected and only accessible within class 'Mock' and its subclasses
Mock has no protected member content. The type checker miss prints the type should be Base.
It is also strange that intersection order matters Mock & Public does not error while Public & Mock
๐ Expected behavior
Ideally no error message. In 6 accessing a field in an intersection that is protected in one of the constituents of the intersection does not fail (most of the time anyway, from what i have seen sometimes the language server shows the same error too)
If not, at least the error message should contain the correct type.
Activity
nmain commentedon Aug 14, 2026
This repros in 6.0 if
stableTypeOrderingis used.RyanCavanaugh commentedon Aug 14, 2026
Intersections are definitely order-dependent (this also matters in e.g. overload resolution); that is not an invariant.
I believe the correct behavior is to allow access if any constituent is public, since that's the more-specific behavior.