[microsoft/TypeScript] [7.0] Can't access field if it is protected in one constituent of an intersection (type order dependent) (Issue #63749)
DRANK
dragomirtitian created an issue (microsoft/TypeScript#63749) ### 🔎 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](https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEkoGdnwCIFcC22Ce8A3gLABQ8F8UAXPAHY4BGIMA3PAPQfwBKI2AewBuCAC4ALAJZoWMATHiS68CQgDmmWMHhqBINFADuUPGQC+ZMqLwAHBAAVMjCJLDwAvPABCKBAB8MHHxWS1JQJDhEaFRvXyIySngbOVFwVO01EFFEATpUvIAKAEpaZFEYJTUQ8kpkgVSwdPhkLJy8kEKhKAhMEFLyyqL2Ll5+YQQAK0wylSk0FtFUhW6IeFl5NF0qY1NSC1IycOhIpBiAWQEwAGt4mopM7LBc-NFi-oq6KoTKBbaXgq6PT6zQGnyGnG4fEEIngUxmEmkzSyS1miJWaxgchgmwE2xM5lCR1gCCedBmhlojmcrjIkgAZvACoZFGTRFA6GAQAIGRdrkVbolDAA6UkvYbcACimPkLPgABUAMrwADs8AJYXAxxJuXJACZaLybgAyeBUlxgMiGXUi54dUShQ6a4ltckAZkpTnN8BNhstrpt7TyFBGUqxssVKrVpCAA) ### 💻 Code ```ts 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_ -- Reply to this email directly or view it on GitHub: https://github.com/microsoft/TypeScript/issues/63749 You are receiving this because you are subscribed to this thread. Message ID: <microsoft/TypeScript/issues/63749@github.com>
👀 github.com/microsoft/Type…