Conversation
…e classes Previously, TS2341 diagnostics in type check blocks were suppressed whenever the accessed property was preceded by `this.` or `(this).`. While this allowed templates and host bindings to access private members declared on their own component or directive class, it also inadvertently suppressed TS2341 when accessing private members inherited from a base class or narrowed subtype, and failed to handle parenthesized, non-null asserted, or optional-chained `this` receivers. Inspect the AST node and symbol declarations via `ts.TypeChecker` when handling TS2341 diagnostics so that private member access is only permitted on `this` when all private declarations of the accessed property belong to the host component or directive class itself. Fixes angular#71032
7b59010 to
15f795e
Compare
|
Hey @JeanMeche, thanks for jumping on #71032! I had a look at the diff and did some digging, but compiler internals aren't really my thing, so I might be off on some of this. A few things I'm wondering about:
Sorry for commenting on a Draft PR, specially if this has been covered already. |
|
Access to private members via |
@wartab you are absolutely right but don't you think that Angular, to some extend, is TypeScript? It has always been written on TypeScript at its core and compiled using a superset of the TypeScript compiler. So everything that has an impact on TypeScript is also our business, IMHO. |
|
What he is saying is that, this is how TS work, so Angular works the same way. Indexed access has always allowed to access private props and probably always will. |
|
Fair enough, makes sense: bracket access is standard TS behavior, so it's out of scope here. Sorry for the mix-up! |
Previously,
TS2341diagnostics in type check blocks were suppressed whenever the accessed property was preceded bythis.or(this).. While this allowed templates and host bindings to accessprivatemembers declared on their own component or directive class (introduced in #70188), it also inadvertently suppressedTS2341when accessingprivatemembers inherited from a base class or narrowed subtype, and failed to handle parenthesized, non-null asserted, or optional-chainedthisreceivers.This commit inspects the AST node and symbol declarations via
ts.TypeCheckerwhen handlingTS2341diagnostics so that private member access is only permitted onthiswhen all private declarations of the accessed property belong to the host component or directive class itself.Fixes #71032