ADocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
protected method in TypeScript is a class member restricted by an access modifier that limits its visibility and invocation exclusively to the declaring class and any derived classes (subclasses) within the inheritance hierarchy. Unlike public methods, it cannot be accessed externally via class instances, and unlike private methods, its accessibility propagates down the prototype chain.
- Internal Access: The method can be invoked using the
thisorsuperkeywords within the defining class and any class thatextendsit. - External Restriction: Attempting to invoke a protected method on an instantiated object results in a
ts(2445)compile-time error. - Visibility Widening: When overriding a
protectedmethod in a derived class, TypeScript permits widening the access modifier topublic. However, the compiler strictly prohibits narrowing the visibility toprivate. - Cross-Instance Access: A class can access the protected methods of other instances of the same class type. However, a derived class cannot access protected members of a base class instance unless the reference is typed as the derived class.
protected modifier introduces nominal typing behavior into TypeScript’s otherwise structural type system. Two classes with identical structural shapes are not type-compatible if their protected members do not originate from the exact same base declaration.
Compilation and Runtime Behavior
The protected keyword is strictly a compile-time construct that is erased during transpilation. In the emitted JavaScript, the method behaves identically to a standard prototype method and is fully accessible at runtime. There is no ECMAScript runtime equivalent for protected encapsulation (unlike ECMAScript # identifiers, which enforce strict runtime privacy but cannot be inherited or combined with TypeScript access modifiers).
Syntax and Behavior Visualization
Master TypeScript with Deep Grasping Methodology!Learn More





