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
Cannot use this to index private or protected properties #17362
I think this is expected given our rules on indexed access types - given that the indexed access operator is defined in terms of keyof T (see here) and keyof T is:
If T has no apparent string index signature, keyof T is a type of the form "p1" | "p2" | ... | "pX", where the string literals represent the names of the public properties of T. If T has no public properties, keyof T is the type never.
So this will require adding an exception whereby private names are actually accessible when indexing this.
As Wesley Wigham (@weswigham) noted, this is the intended behavior. it becomes very hard to reason about these types in higher order if you have to carry around a context to know if the name is visible or not.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
weswigham commentedon Jul 24, 2017
I think this is expected given our rules on indexed access types - given that the indexed access operator is defined in terms of
keyof T(see here) andkeyof Tis:So this will require adding an exception whereby private names are actually accessible when indexing
this.Pauan commentedon Jul 25, 2017
Wesley Wigham (@weswigham) But
Foo["_foo"]is the same situation, and it works fine.So does indexing on classes have an exception for private/protected members, but that exception wasn't applied to
this?mhegazy commentedon Nov 9, 2017
As Wesley Wigham (@weswigham) noted, this is the intended behavior. it becomes very hard to reason about these types in higher order if you have to carry around a context to know if the name is visible or not.
typescript-bot commentedon Nov 27, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.