Allow base constructor types to be intersections

This commit is contained in:
Anders Hejlsberg 2017-01-20 09:17:14 -08:00
parent a9af10b030
commit c16c7d56c0

View File

@ -3810,7 +3810,7 @@ namespace ts {
}
function isConstructorType(type: Type): boolean {
return type.flags & TypeFlags.Object && getSignaturesOfType(type, SignatureKind.Construct).length > 0;
return isValidBaseType(type) && getSignaturesOfType(type, SignatureKind.Construct).length > 0;
}
function getBaseTypeNodeOfClass(type: InterfaceType): ExpressionWithTypeArguments {
@ -3849,7 +3849,7 @@ namespace ts {
return unknownType;
}
const baseConstructorType = checkExpression(baseTypeNode.expression);
if (baseConstructorType.flags & TypeFlags.Object) {
if (baseConstructorType.flags & (TypeFlags.Object | TypeFlags.Intersection)) {
// Resolving the members of a class requires us to resolve the base class of that class.
// We force resolution here such that we catch circularities now.
resolveStructuredTypeMembers(<ObjectType>baseConstructorType);
@ -3890,7 +3890,7 @@ namespace ts {
function resolveBaseTypesOfClass(type: InterfaceType): void {
type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray;
const baseConstructorType = <ObjectType>getBaseConstructorTypeOfClass(type);
if (!(baseConstructorType.flags & TypeFlags.Object)) {
if (!(baseConstructorType.flags & (TypeFlags.Object | TypeFlags.Intersection))) {
return;
}
const baseTypeNode = getBaseTypeNodeOfClass(type);
@ -4591,9 +4591,9 @@ namespace ts {
constructSignatures = getDefaultConstructSignatures(classType);
}
const baseConstructorType = getBaseConstructorTypeOfClass(classType);
if (baseConstructorType.flags & TypeFlags.Object) {
if (baseConstructorType.flags & (TypeFlags.Object | TypeFlags.Intersection)) {
members = createSymbolTable(getNamedMembers(members));
addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType));
addInheritedMembers(members, getPropertiesOfType(baseConstructorType));
}
}
const numberIndexInfo = symbol.flags & SymbolFlags.Enum ? enumNumberIndexInfo : undefined;