diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b764348cc6f10..6dd29e3a409a7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10937,24 +10937,33 @@ namespace ts { const types = type.types; const mixinFlags = findMixins(types); const mixinCount = countWhere(mixinFlags, (b) => b); + const allTypeSignatures = types.map((t) => getSignaturesOfType(t, SignatureKind.Construct)); + // Flag mixins with only publicly accessible constructors + const accessibleMixinFlags = mixinFlags.map((flag, i) => flag && allTypeSignatures[i].every(({declaration}) => declaration && !getSelectedEffectiveModifierFlags(declaration, ModifierFlags.NonPublicAccessibilityModifier))); for (let i = 0; i < types.length; i++) { - const t = type.types[i]; - // When an intersection type contains mixin constructor types, the construct signatures from - // those types are discarded and their return types are mixed into the return types of all - // other construct signatures in the intersection type. For example, the intersection type - // '{ new(...args: any[]) => A } & { new(s: string) => B }' has a single construct signature - // 'new(s: string) => A & B'. - if (!mixinFlags[i]) { - let signatures = getSignaturesOfType(t, SignatureKind.Construct); - if (signatures.length && mixinCount > 0) { - signatures = map(signatures, s => { - const clone = cloneSignature(s); - clone.resolvedReturnType = includeMixinType(getReturnTypeOfSignature(s), types, mixinFlags, i); - return clone; - }); - } - constructSignatures = appendSignatures(constructSignatures, signatures); + const t = types[i]; + let signatures = allTypeSignatures[i]; + // When an intersection type contains mixin constructor types... + if (mixinFlags[i]) { + // ...the NON-PUBLICLY ACCESSIBLE construct signatures (private, protected) from those mixin types + // are kept and added to the intersection type construct signatures + signatures = signatures.filter(({declaration}) => declaration && getSelectedEffectiveModifierFlags(declaration, ModifierFlags.NonPublicAccessibilityModifier)); + } + else if (signatures.length && mixinCount > 0) { + // ...the PUBLICLY ACCESSIBLE construct signatures from those mixin types + // are discarded and their return types are mixed into the return types of all + // other construct signatures in the intersection type. For example, the intersection type + // '{ new(...args: any[]) => A } & { new(s: string) => B }' has a single construct signature + // 'new(s: string) => A & B'. + signatures = map(signatures, s => { + const clone = cloneSignature(s); + // accessibleMixinFlags is used here to prevent the return types of construct signatures of mixins with non-public constructors + // getting mixed into the intersection type's construct signatures. + clone.resolvedReturnType = includeMixinType(getReturnTypeOfSignature(s), types, accessibleMixinFlags, i); + return clone; + }); } + constructSignatures = appendSignatures(constructSignatures, signatures); callSignatures = appendSignatures(callSignatures, getSignaturesOfType(t, SignatureKind.Call)); indexInfos = reduceLeft(getIndexInfosOfType(t), (infos, newInfo) => appendIndexInfo(infos, newInfo, /*union*/ false), indexInfos); } diff --git a/tests/baselines/reference/mixinClassesConstructorAccessibility.errors.txt b/tests/baselines/reference/mixinClassesConstructorAccessibility.errors.txt new file mode 100644 index 0000000000000..f62272bfb6aec --- /dev/null +++ b/tests/baselines/reference/mixinClassesConstructorAccessibility.errors.txt @@ -0,0 +1,75 @@ +tests/cases/conformance/classes/mixinClassesConstructorAccessibility.ts(53,3): error TS2673: Constructor of class 'PrivateConstructorMixin' is private and only accessible within the class declaration. +tests/cases/conformance/classes/mixinClassesConstructorAccessibility.ts(54,3): error TS2673: Constructor of class 'PrivateConstructorMixinGenericBaseType' is private and only accessible within the class declaration. +tests/cases/conformance/classes/mixinClassesConstructorAccessibility.ts(56,3): error TS2674: Constructor of class 'ProtectedConstructorMixin' is protected and only accessible within the class declaration. +tests/cases/conformance/classes/mixinClassesConstructorAccessibility.ts(57,3): error TS2674: Constructor of class 'ProtectedConstructorMixinGenericBaseType' is protected and only accessible within the class declaration. + + +==== tests/cases/conformance/classes/mixinClassesConstructorAccessibility.ts (4 errors) ==== + function PrivateConstructorMixinGenericBaseType any>(Base: TBase) { + return class PrivateConstructorMixinGenericBaseType extends Base { + private constructor(...args: any[]) { + super(); + } + } + } + + function PrivateConstructorMixin(Base: new(...args: any[]) => any) { + return class PrivateConstructorMixin extends Base { + private constructor(...args: any[]) { + super(); + } + } + } + + function ProtectedConstructorMixinGenericBaseType any>(Base: TBase) { + return class ProtectedConstructorMixinGenericBaseType extends Base { + protected constructor(...args: any[]) { + super(); + } + } + } + + function ProtectedConstructorMixin(Base: new(...args: any[]) => any) { + return class ProtectedConstructorMixin extends Base { + protected constructor(...args: any[]) { + super(); + } + } + } + + function PublicConstructorMixinGenericBaseType(Base: new(...args: any[]) => any) { + return class PublicConstructorMixinGenericBaseType extends Base { + constructor(...args: any[]) { + super(); + } + } + } + + function PublicConstructorMixin(Base: new(...args: any[]) => any) { + return class PublicConstructorMixin extends Base { + constructor(...args: any[]) { + super(); + } + } + } + + class Base { + constructor() {} + } + + new (PrivateConstructorMixin(Base))(); // error: PrivateConstructorMixin is private + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2673: Constructor of class 'PrivateConstructorMixin' is private and only accessible within the class declaration. + new (PrivateConstructorMixinGenericBaseType(Base))(); // error: PrivateConstructorMixinGenericBaseType is private + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2673: Constructor of class 'PrivateConstructorMixinGenericBaseType' is private and only accessible within the class declaration. + + new (ProtectedConstructorMixin(Base))(); // error: ProtectedConstructorMixin is protected + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2674: Constructor of class 'ProtectedConstructorMixin' is protected and only accessible within the class declaration. + new (ProtectedConstructorMixinGenericBaseType(Base))(); // error: ProtectedConstructorMixinGenericBaseType is protected + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2674: Constructor of class 'ProtectedConstructorMixinGenericBaseType' is protected and only accessible within the class declaration. + + new (PublicConstructorMixin(Base))(); + new (PublicConstructorMixinGenericBaseType(Base))(); \ No newline at end of file diff --git a/tests/baselines/reference/mixinClassesConstructorAccessibility.js b/tests/baselines/reference/mixinClassesConstructorAccessibility.js new file mode 100644 index 0000000000000..e6f744ea534e6 --- /dev/null +++ b/tests/baselines/reference/mixinClassesConstructorAccessibility.js @@ -0,0 +1,167 @@ +//// [mixinClassesConstructorAccessibility.ts] +function PrivateConstructorMixinGenericBaseType any>(Base: TBase) { + return class PrivateConstructorMixinGenericBaseType extends Base { + private constructor(...args: any[]) { + super(); + } + } + } + + function PrivateConstructorMixin(Base: new(...args: any[]) => any) { + return class PrivateConstructorMixin extends Base { + private constructor(...args: any[]) { + super(); + } + } + } + + function ProtectedConstructorMixinGenericBaseType any>(Base: TBase) { + return class ProtectedConstructorMixinGenericBaseType extends Base { + protected constructor(...args: any[]) { + super(); + } + } + } + + function ProtectedConstructorMixin(Base: new(...args: any[]) => any) { + return class ProtectedConstructorMixin extends Base { + protected constructor(...args: any[]) { + super(); + } + } + } + + function PublicConstructorMixinGenericBaseType(Base: new(...args: any[]) => any) { + return class PublicConstructorMixinGenericBaseType extends Base { + constructor(...args: any[]) { + super(); + } + } + } + + function PublicConstructorMixin(Base: new(...args: any[]) => any) { + return class PublicConstructorMixin extends Base { + constructor(...args: any[]) { + super(); + } + } + } + + class Base { + constructor() {} + } + + new (PrivateConstructorMixin(Base))(); // error: PrivateConstructorMixin is private + new (PrivateConstructorMixinGenericBaseType(Base))(); // error: PrivateConstructorMixinGenericBaseType is private + + new (ProtectedConstructorMixin(Base))(); // error: ProtectedConstructorMixin is protected + new (ProtectedConstructorMixinGenericBaseType(Base))(); // error: ProtectedConstructorMixinGenericBaseType is protected + + new (PublicConstructorMixin(Base))(); + new (PublicConstructorMixinGenericBaseType(Base))(); + +//// [mixinClassesConstructorAccessibility.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +function PrivateConstructorMixinGenericBaseType(Base) { + return /** @class */ (function (_super) { + __extends(PrivateConstructorMixinGenericBaseType, _super); + function PrivateConstructorMixinGenericBaseType() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return _super.call(this) || this; + } + return PrivateConstructorMixinGenericBaseType; + }(Base)); +} +function PrivateConstructorMixin(Base) { + return /** @class */ (function (_super) { + __extends(PrivateConstructorMixin, _super); + function PrivateConstructorMixin() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return _super.call(this) || this; + } + return PrivateConstructorMixin; + }(Base)); +} +function ProtectedConstructorMixinGenericBaseType(Base) { + return /** @class */ (function (_super) { + __extends(ProtectedConstructorMixinGenericBaseType, _super); + function ProtectedConstructorMixinGenericBaseType() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return _super.call(this) || this; + } + return ProtectedConstructorMixinGenericBaseType; + }(Base)); +} +function ProtectedConstructorMixin(Base) { + return /** @class */ (function (_super) { + __extends(ProtectedConstructorMixin, _super); + function ProtectedConstructorMixin() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return _super.call(this) || this; + } + return ProtectedConstructorMixin; + }(Base)); +} +function PublicConstructorMixinGenericBaseType(Base) { + return /** @class */ (function (_super) { + __extends(PublicConstructorMixinGenericBaseType, _super); + function PublicConstructorMixinGenericBaseType() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return _super.call(this) || this; + } + return PublicConstructorMixinGenericBaseType; + }(Base)); +} +function PublicConstructorMixin(Base) { + return /** @class */ (function (_super) { + __extends(PublicConstructorMixin, _super); + function PublicConstructorMixin() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return _super.call(this) || this; + } + return PublicConstructorMixin; + }(Base)); +} +var Base = /** @class */ (function () { + function Base() { + } + return Base; +}()); +new (PrivateConstructorMixin(Base))(); // error: PrivateConstructorMixin is private +new (PrivateConstructorMixinGenericBaseType(Base))(); // error: PrivateConstructorMixinGenericBaseType is private +new (ProtectedConstructorMixin(Base))(); // error: ProtectedConstructorMixin is protected +new (ProtectedConstructorMixinGenericBaseType(Base))(); // error: ProtectedConstructorMixinGenericBaseType is protected +new (PublicConstructorMixin(Base))(); +new (PublicConstructorMixinGenericBaseType(Base))(); diff --git a/tests/baselines/reference/mixinClassesConstructorAccessibility.symbols b/tests/baselines/reference/mixinClassesConstructorAccessibility.symbols new file mode 100644 index 0000000000000..d7cf435f401f6 --- /dev/null +++ b/tests/baselines/reference/mixinClassesConstructorAccessibility.symbols @@ -0,0 +1,143 @@ +=== tests/cases/conformance/classes/mixinClassesConstructorAccessibility.ts === +function PrivateConstructorMixinGenericBaseType any>(Base: TBase) { +>PrivateConstructorMixinGenericBaseType : Symbol(PrivateConstructorMixinGenericBaseType, Decl(mixinClassesConstructorAccessibility.ts, 0, 0)) +>TBase : Symbol(TBase, Decl(mixinClassesConstructorAccessibility.ts, 0, 48)) +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 0, 66)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 0, 90)) +>TBase : Symbol(TBase, Decl(mixinClassesConstructorAccessibility.ts, 0, 48)) + + return class PrivateConstructorMixinGenericBaseType extends Base { +>PrivateConstructorMixinGenericBaseType : Symbol(PrivateConstructorMixinGenericBaseType, Decl(mixinClassesConstructorAccessibility.ts, 1, 10)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 0, 90)) + + private constructor(...args: any[]) { +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 2, 26)) + + super(); +>super : Symbol(TBase, Decl(mixinClassesConstructorAccessibility.ts, 0, 48)) + } + } + } + + function PrivateConstructorMixin(Base: new(...args: any[]) => any) { +>PrivateConstructorMixin : Symbol(PrivateConstructorMixin, Decl(mixinClassesConstructorAccessibility.ts, 6, 3)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 8, 35)) +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 8, 45)) + + return class PrivateConstructorMixin extends Base { +>PrivateConstructorMixin : Symbol(PrivateConstructorMixin, Decl(mixinClassesConstructorAccessibility.ts, 9, 10)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 8, 35)) + + private constructor(...args: any[]) { +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 10, 26)) + + super(); +>super : Symbol(__type, Decl(mixinClassesConstructorAccessibility.ts, 8, 40)) + } + } + } + + function ProtectedConstructorMixinGenericBaseType any>(Base: TBase) { +>ProtectedConstructorMixinGenericBaseType : Symbol(ProtectedConstructorMixinGenericBaseType, Decl(mixinClassesConstructorAccessibility.ts, 14, 3)) +>TBase : Symbol(TBase, Decl(mixinClassesConstructorAccessibility.ts, 16, 52)) +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 16, 70)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 16, 94)) +>TBase : Symbol(TBase, Decl(mixinClassesConstructorAccessibility.ts, 16, 52)) + + return class ProtectedConstructorMixinGenericBaseType extends Base { +>ProtectedConstructorMixinGenericBaseType : Symbol(ProtectedConstructorMixinGenericBaseType, Decl(mixinClassesConstructorAccessibility.ts, 17, 10)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 16, 94)) + + protected constructor(...args: any[]) { +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 18, 28)) + + super(); +>super : Symbol(TBase, Decl(mixinClassesConstructorAccessibility.ts, 16, 52)) + } + } + } + + function ProtectedConstructorMixin(Base: new(...args: any[]) => any) { +>ProtectedConstructorMixin : Symbol(ProtectedConstructorMixin, Decl(mixinClassesConstructorAccessibility.ts, 22, 3)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 24, 37)) +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 24, 47)) + + return class ProtectedConstructorMixin extends Base { +>ProtectedConstructorMixin : Symbol(ProtectedConstructorMixin, Decl(mixinClassesConstructorAccessibility.ts, 25, 10)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 24, 37)) + + protected constructor(...args: any[]) { +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 26, 28)) + + super(); +>super : Symbol(__type, Decl(mixinClassesConstructorAccessibility.ts, 24, 42)) + } + } + } + + function PublicConstructorMixinGenericBaseType(Base: new(...args: any[]) => any) { +>PublicConstructorMixinGenericBaseType : Symbol(PublicConstructorMixinGenericBaseType, Decl(mixinClassesConstructorAccessibility.ts, 30, 3)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 32, 49)) +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 32, 59)) + + return class PublicConstructorMixinGenericBaseType extends Base { +>PublicConstructorMixinGenericBaseType : Symbol(PublicConstructorMixinGenericBaseType, Decl(mixinClassesConstructorAccessibility.ts, 33, 10)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 32, 49)) + + constructor(...args: any[]) { +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 34, 18)) + + super(); +>super : Symbol(__type, Decl(mixinClassesConstructorAccessibility.ts, 32, 54)) + } + } + } + + function PublicConstructorMixin(Base: new(...args: any[]) => any) { +>PublicConstructorMixin : Symbol(PublicConstructorMixin, Decl(mixinClassesConstructorAccessibility.ts, 38, 3)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 40, 34)) +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 40, 44)) + + return class PublicConstructorMixin extends Base { +>PublicConstructorMixin : Symbol(PublicConstructorMixin, Decl(mixinClassesConstructorAccessibility.ts, 41, 10)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 40, 34)) + + constructor(...args: any[]) { +>args : Symbol(args, Decl(mixinClassesConstructorAccessibility.ts, 42, 18)) + + super(); +>super : Symbol(__type, Decl(mixinClassesConstructorAccessibility.ts, 40, 39)) + } + } + } + + class Base { +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 46, 3)) + + constructor() {} + } + + new (PrivateConstructorMixin(Base))(); // error: PrivateConstructorMixin is private +>PrivateConstructorMixin : Symbol(PrivateConstructorMixin, Decl(mixinClassesConstructorAccessibility.ts, 6, 3)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 46, 3)) + + new (PrivateConstructorMixinGenericBaseType(Base))(); // error: PrivateConstructorMixinGenericBaseType is private +>PrivateConstructorMixinGenericBaseType : Symbol(PrivateConstructorMixinGenericBaseType, Decl(mixinClassesConstructorAccessibility.ts, 0, 0)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 46, 3)) + + new (ProtectedConstructorMixin(Base))(); // error: ProtectedConstructorMixin is protected +>ProtectedConstructorMixin : Symbol(ProtectedConstructorMixin, Decl(mixinClassesConstructorAccessibility.ts, 22, 3)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 46, 3)) + + new (ProtectedConstructorMixinGenericBaseType(Base))(); // error: ProtectedConstructorMixinGenericBaseType is protected +>ProtectedConstructorMixinGenericBaseType : Symbol(ProtectedConstructorMixinGenericBaseType, Decl(mixinClassesConstructorAccessibility.ts, 14, 3)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 46, 3)) + + new (PublicConstructorMixin(Base))(); +>PublicConstructorMixin : Symbol(PublicConstructorMixin, Decl(mixinClassesConstructorAccessibility.ts, 38, 3)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 46, 3)) + + new (PublicConstructorMixinGenericBaseType(Base))(); +>PublicConstructorMixinGenericBaseType : Symbol(PublicConstructorMixinGenericBaseType, Decl(mixinClassesConstructorAccessibility.ts, 30, 3)) +>Base : Symbol(Base, Decl(mixinClassesConstructorAccessibility.ts, 46, 3)) + diff --git a/tests/baselines/reference/mixinClassesConstructorAccessibility.types b/tests/baselines/reference/mixinClassesConstructorAccessibility.types new file mode 100644 index 0000000000000..2b8a5b0dae371 --- /dev/null +++ b/tests/baselines/reference/mixinClassesConstructorAccessibility.types @@ -0,0 +1,169 @@ +=== tests/cases/conformance/classes/mixinClassesConstructorAccessibility.ts === +function PrivateConstructorMixinGenericBaseType any>(Base: TBase) { +>PrivateConstructorMixinGenericBaseType : any>(Base: TBase) => { new (...args: any[]): PrivateConstructorMixinGenericBaseType; prototype: PrivateConstructorMixinGenericBaseType.PrivateConstructorMixinGenericBaseType; } & TBase +>args : any[] +>Base : TBase + + return class PrivateConstructorMixinGenericBaseType extends Base { +>class PrivateConstructorMixinGenericBaseType extends Base { private constructor(...args: any[]) { super(); } } : { new (...args: any[]): PrivateConstructorMixinGenericBaseType; prototype: PrivateConstructorMixinGenericBaseType.PrivateConstructorMixinGenericBaseType; } & TBase +>PrivateConstructorMixinGenericBaseType : { new (...args: any[]): PrivateConstructorMixinGenericBaseType; prototype: PrivateConstructorMixinGenericBaseType.PrivateConstructorMixinGenericBaseType; } & TBase +>Base : TBase + + private constructor(...args: any[]) { +>args : any[] + + super(); +>super() : void +>super : TBase + } + } + } + + function PrivateConstructorMixin(Base: new(...args: any[]) => any) { +>PrivateConstructorMixin : (Base: new (...args: any[]) => any) => typeof PrivateConstructorMixin +>Base : new (...args: any[]) => any +>args : any[] + + return class PrivateConstructorMixin extends Base { +>class PrivateConstructorMixin extends Base { private constructor(...args: any[]) { super(); } } : typeof PrivateConstructorMixin +>PrivateConstructorMixin : typeof PrivateConstructorMixin +>Base : new (...args: any[]) => any + + private constructor(...args: any[]) { +>args : any[] + + super(); +>super() : void +>super : new (...args: any[]) => any + } + } + } + + function ProtectedConstructorMixinGenericBaseType any>(Base: TBase) { +>ProtectedConstructorMixinGenericBaseType : any>(Base: TBase) => { new (...args: any[]): ProtectedConstructorMixinGenericBaseType; prototype: ProtectedConstructorMixinGenericBaseType.ProtectedConstructorMixinGenericBaseType; } & TBase +>args : any[] +>Base : TBase + + return class ProtectedConstructorMixinGenericBaseType extends Base { +>class ProtectedConstructorMixinGenericBaseType extends Base { protected constructor(...args: any[]) { super(); } } : { new (...args: any[]): ProtectedConstructorMixinGenericBaseType; prototype: ProtectedConstructorMixinGenericBaseType.ProtectedConstructorMixinGenericBaseType; } & TBase +>ProtectedConstructorMixinGenericBaseType : { new (...args: any[]): ProtectedConstructorMixinGenericBaseType; prototype: ProtectedConstructorMixinGenericBaseType.ProtectedConstructorMixinGenericBaseType; } & TBase +>Base : TBase + + protected constructor(...args: any[]) { +>args : any[] + + super(); +>super() : void +>super : TBase + } + } + } + + function ProtectedConstructorMixin(Base: new(...args: any[]) => any) { +>ProtectedConstructorMixin : (Base: new (...args: any[]) => any) => typeof ProtectedConstructorMixin +>Base : new (...args: any[]) => any +>args : any[] + + return class ProtectedConstructorMixin extends Base { +>class ProtectedConstructorMixin extends Base { protected constructor(...args: any[]) { super(); } } : typeof ProtectedConstructorMixin +>ProtectedConstructorMixin : typeof ProtectedConstructorMixin +>Base : new (...args: any[]) => any + + protected constructor(...args: any[]) { +>args : any[] + + super(); +>super() : void +>super : new (...args: any[]) => any + } + } + } + + function PublicConstructorMixinGenericBaseType(Base: new(...args: any[]) => any) { +>PublicConstructorMixinGenericBaseType : (Base: new (...args: any[]) => any) => typeof PublicConstructorMixinGenericBaseType +>Base : new (...args: any[]) => any +>args : any[] + + return class PublicConstructorMixinGenericBaseType extends Base { +>class PublicConstructorMixinGenericBaseType extends Base { constructor(...args: any[]) { super(); } } : typeof PublicConstructorMixinGenericBaseType +>PublicConstructorMixinGenericBaseType : typeof PublicConstructorMixinGenericBaseType +>Base : new (...args: any[]) => any + + constructor(...args: any[]) { +>args : any[] + + super(); +>super() : void +>super : new (...args: any[]) => any + } + } + } + + function PublicConstructorMixin(Base: new(...args: any[]) => any) { +>PublicConstructorMixin : (Base: new (...args: any[]) => any) => typeof PublicConstructorMixin +>Base : new (...args: any[]) => any +>args : any[] + + return class PublicConstructorMixin extends Base { +>class PublicConstructorMixin extends Base { constructor(...args: any[]) { super(); } } : typeof PublicConstructorMixin +>PublicConstructorMixin : typeof PublicConstructorMixin +>Base : new (...args: any[]) => any + + constructor(...args: any[]) { +>args : any[] + + super(); +>super() : void +>super : new (...args: any[]) => any + } + } + } + + class Base { +>Base : Base + + constructor() {} + } + + new (PrivateConstructorMixin(Base))(); // error: PrivateConstructorMixin is private +>new (PrivateConstructorMixin(Base))() : any +>(PrivateConstructorMixin(Base)) : typeof PrivateConstructorMixin +>PrivateConstructorMixin(Base) : typeof PrivateConstructorMixin +>PrivateConstructorMixin : (Base: new (...args: any[]) => any) => typeof PrivateConstructorMixin +>Base : typeof Base + + new (PrivateConstructorMixinGenericBaseType(Base))(); // error: PrivateConstructorMixinGenericBaseType is private +>new (PrivateConstructorMixinGenericBaseType(Base))() : any +>(PrivateConstructorMixinGenericBaseType(Base)) : { new (...args: any[]): PrivateConstructorMixinGenericBaseType.PrivateConstructorMixinGenericBaseType; prototype: PrivateConstructorMixinGenericBaseType.PrivateConstructorMixinGenericBaseType; } & typeof Base +>PrivateConstructorMixinGenericBaseType(Base) : { new (...args: any[]): PrivateConstructorMixinGenericBaseType.PrivateConstructorMixinGenericBaseType; prototype: PrivateConstructorMixinGenericBaseType.PrivateConstructorMixinGenericBaseType; } & typeof Base +>PrivateConstructorMixinGenericBaseType : any>(Base: TBase) => { new (...args: any[]): PrivateConstructorMixinGenericBaseType; prototype: PrivateConstructorMixinGenericBaseType.PrivateConstructorMixinGenericBaseType; } & TBase +>Base : typeof Base + + new (ProtectedConstructorMixin(Base))(); // error: ProtectedConstructorMixin is protected +>new (ProtectedConstructorMixin(Base))() : any +>(ProtectedConstructorMixin(Base)) : typeof ProtectedConstructorMixin +>ProtectedConstructorMixin(Base) : typeof ProtectedConstructorMixin +>ProtectedConstructorMixin : (Base: new (...args: any[]) => any) => typeof ProtectedConstructorMixin +>Base : typeof Base + + new (ProtectedConstructorMixinGenericBaseType(Base))(); // error: ProtectedConstructorMixinGenericBaseType is protected +>new (ProtectedConstructorMixinGenericBaseType(Base))() : any +>(ProtectedConstructorMixinGenericBaseType(Base)) : { new (...args: any[]): ProtectedConstructorMixinGenericBaseType.ProtectedConstructorMixinGenericBaseType; prototype: ProtectedConstructorMixinGenericBaseType.ProtectedConstructorMixinGenericBaseType; } & typeof Base +>ProtectedConstructorMixinGenericBaseType(Base) : { new (...args: any[]): ProtectedConstructorMixinGenericBaseType.ProtectedConstructorMixinGenericBaseType; prototype: ProtectedConstructorMixinGenericBaseType.ProtectedConstructorMixinGenericBaseType; } & typeof Base +>ProtectedConstructorMixinGenericBaseType : any>(Base: TBase) => { new (...args: any[]): ProtectedConstructorMixinGenericBaseType; prototype: ProtectedConstructorMixinGenericBaseType.ProtectedConstructorMixinGenericBaseType; } & TBase +>Base : typeof Base + + new (PublicConstructorMixin(Base))(); +>new (PublicConstructorMixin(Base))() : PublicConstructorMixin +>(PublicConstructorMixin(Base)) : typeof PublicConstructorMixin +>PublicConstructorMixin(Base) : typeof PublicConstructorMixin +>PublicConstructorMixin : (Base: new (...args: any[]) => any) => typeof PublicConstructorMixin +>Base : typeof Base + + new (PublicConstructorMixinGenericBaseType(Base))(); +>new (PublicConstructorMixinGenericBaseType(Base))() : PublicConstructorMixinGenericBaseType +>(PublicConstructorMixinGenericBaseType(Base)) : typeof PublicConstructorMixinGenericBaseType +>PublicConstructorMixinGenericBaseType(Base) : typeof PublicConstructorMixinGenericBaseType +>PublicConstructorMixinGenericBaseType : (Base: new (...args: any[]) => any) => typeof PublicConstructorMixinGenericBaseType +>Base : typeof Base + diff --git a/tests/cases/conformance/classes/mixinClassesConstructorAccessibility.ts b/tests/cases/conformance/classes/mixinClassesConstructorAccessibility.ts new file mode 100644 index 0000000000000..1de0f0e80976a --- /dev/null +++ b/tests/cases/conformance/classes/mixinClassesConstructorAccessibility.ts @@ -0,0 +1,60 @@ +function PrivateConstructorMixinGenericBaseType any>(Base: TBase) { + return class PrivateConstructorMixinGenericBaseType extends Base { + private constructor(...args: any[]) { + super(); + } + } + } + + function PrivateConstructorMixin(Base: new(...args: any[]) => any) { + return class PrivateConstructorMixin extends Base { + private constructor(...args: any[]) { + super(); + } + } + } + + function ProtectedConstructorMixinGenericBaseType any>(Base: TBase) { + return class ProtectedConstructorMixinGenericBaseType extends Base { + protected constructor(...args: any[]) { + super(); + } + } + } + + function ProtectedConstructorMixin(Base: new(...args: any[]) => any) { + return class ProtectedConstructorMixin extends Base { + protected constructor(...args: any[]) { + super(); + } + } + } + + function PublicConstructorMixinGenericBaseType(Base: new(...args: any[]) => any) { + return class PublicConstructorMixinGenericBaseType extends Base { + constructor(...args: any[]) { + super(); + } + } + } + + function PublicConstructorMixin(Base: new(...args: any[]) => any) { + return class PublicConstructorMixin extends Base { + constructor(...args: any[]) { + super(); + } + } + } + + class Base { + constructor() {} + } + + new (PrivateConstructorMixin(Base))(); // error: PrivateConstructorMixin is private + new (PrivateConstructorMixinGenericBaseType(Base))(); // error: PrivateConstructorMixinGenericBaseType is private + + new (ProtectedConstructorMixin(Base))(); // error: ProtectedConstructorMixin is protected + new (ProtectedConstructorMixinGenericBaseType(Base))(); // error: ProtectedConstructorMixinGenericBaseType is protected + + new (PublicConstructorMixin(Base))(); + new (PublicConstructorMixinGenericBaseType(Base))(); \ No newline at end of file