microsoft / microsoft/TypeScript
Protected nested classes
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the three TypeScript examples from the issue, including the namespace workaround and the subclass extension case. Trace how the compiler resolves nested class types and protected static members, then add regression coverage showing that the valid examples compile without errors while protected access remains enforced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100