mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 10:00:13 -06:00
Protected ctors are accessible in subclass static methods
Previously, it was an error to refer to a protected constructor from a base class, even in a static method where the semantics work. Now it is not an error in static methods.
This commit is contained in:
parent
25525607d5
commit
97ef839a03
@ -11544,8 +11544,23 @@ namespace ts {
|
||||
const declaringClassDeclaration = <ClassLikeDeclaration>getClassLikeDeclarationOfSymbol(declaration.parent.symbol);
|
||||
const declaringClass = <InterfaceType>getDeclaredTypeOfSymbol(declaration.parent.symbol);
|
||||
|
||||
// A private or protected constructor can only be instantiated within it's own class
|
||||
// A private or protected constructor can only be instantiated within its own class or a static method of a subclass
|
||||
if (!isNodeWithinClass(node, declaringClassDeclaration)) {
|
||||
const containingFunction = getContainingFunction(node);
|
||||
const containingClass = getContainingClass(node);
|
||||
if (containingClass) {
|
||||
const containingType = getTypeOfNode(containingClass);
|
||||
const baseTypes = getBaseTypes(<InterfaceType>containingType);
|
||||
if (baseTypes.length) {
|
||||
const baseType = baseTypes[0];
|
||||
if (containingFunction &&
|
||||
containingFunction.flags & NodeFlags.Static &&
|
||||
flags & NodeFlags.Protected &&
|
||||
baseType.symbol === declaration.parent.symbol) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flags & NodeFlags.Private) {
|
||||
error(node, Diagnostics.Constructor_of_class_0_is_private_and_only_accessible_within_the_class_declaration, typeToString(declaringClass));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user