Protected nested classes
See original GitHub issueTypeScript Version: 1.8.9
Code
class Outer {
protected static Inner = class {}
private myInner: Outer.Inner;
}
Expected behavior: No errors.
Actual behavior: Compiler error: Cannot find namespace 'Outer'. Line 3, Column 24
Code
class Outer {
protected static Inner = class {}
private myInner: Outer.Inner;
}
namespace Outer {}
Expected behavior: No errors.
Actual behavior: Compiler error: Module 'Outer' has no exported member 'Inner'. Line 3, Column 32
Code
export class Outer {
protected static Inner = class {};
}
export class Child extends Outer {
static temp = class extends Outer.Inner {}
}
Expected behavior: No errors.
Actual behavior: Compiler error: Property 'Inner' is protected and only accessible within class 'Outer' and its subclasses. Line 6, Column 35
The problem here is that there is no way to define a protected nested class in a way that makes it possible to use in a type declaration. The third example shows why I want to use this: I want a nested class that can only be extended by classes that extend the parent class.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:18
- Comments:5 (3 by maintainers)
Top Results From Across the Web
protected/public Inner Classes - java - Stack Overflow
You can just think protected inner class is protected member, so it only access for class, package, subclass but not for the world....
Read more >Nested Classes - Learning the Java Language
A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing...
Read more >Nested classes - cppreference.com
Like any member of its enclosing class, the nested class has access to all names (private, protected, etc) to which the enclosing class...
Read more >Nested Types - C# Programming Guide | Microsoft Learn
Nested types of a class can be public, protected, internal, protected internal, private or private protected. However, defining a protected , ...
Read more >Nested Classes in Java - GeeksforGeeks
As a member of its enclosing class, a nested class can be declared private, public, protected, or package private(default). Nested classes are ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The compilation error for the first example now (in Typescript 3) reads:
'Outer' only refers to a type, but is being used as a namespace here.
I’m not sure if there’s a better way to do this but I managed to get it to compile using this workaround:
It seems there is a different error in Example 3 in 3.3.3 and later.
And it is possible to inherite from a public reference to the protected nested class.