π Search Terms
intersection type protected member order, TS2445, instanceof narrowing protected intersection, intersection not commutative
π Version & Regression Information
- This changed between versions 6.0 and 7.0
β― Playground Link
Playground Link
π» Code
declare class Dummy {
a: number; // Remove this error in the guard goes away
}
type Public = Base | Dummy;
declare class Base {
protected get content(): string;
protected set content(value: string); // Remove just this setter all errors go away
}
declare class Mock {
get content(): string;
set content(value: string); // Remove just this setter this all errors go away
}
declare const w: Public
if (w instanceof Mock) {
w.content; // Error in TS 7
}
declare const w2: Mock & Public
w2.content
declare const w3: Public & Mock
w3.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.
Additional information about the issue
No response
π Search Terms
intersection type protected member order, TS2445, instanceof narrowing protected intersection, intersection not commutative
π Version & Regression Information
β― Playground Link
Playground Link
π» Code
π Actual behavior
The marked lines fail to type check with:
Mockhas no protected membercontent. The type checker miss prints the type should beBase.It is also strange that intersection order matters
Mock & Publicdoes not error whilePublic & 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.
Additional information about the issue
No response