user1354934 user1354934 - 5 months ago 27
TypeScript Question

In TypeScript, how can I fix an error "property ____ is protected and only accessible within class ____"?

I am working on an angular 2 project and I am using a library called


I am using modals from this library, and there is a property called
that I am checking in a function inside my class:

proceed() {
if (this.childModal._isShown) this.hideChildModal(); // error message here: "[ts] Property '_isShown' is protected and only accessible within class 'ModalDirective' and its subclasses."

It seems to work even though I get that error, but how can I fix that error correctly?



Because _isShown is protected in ModalDirective source code. Check it out here.

You can access the public value using isShown() function.

It is declared as public in the source code.

  public get isShown(): boolean {
    return this._isShown;