@@ -3599,6 +3599,10 @@ module ts {
3599
3599
return type;
3600
3600
}
3601
3601
3602
+ function getUnionTypeOfSubtypeConstituents(source: UnionType, target: Type): Type {
3603
+ return getUnionType(filter(source.types, t => isTypeSubtypeOf(t, target)));
3604
+ }
3605
+
3602
3606
function getReducedTypeOfUnionType(type: UnionType): Type {
3603
3607
// If union type was created without subtype reduction, perform the deferred reduction now
3604
3608
if (!type.reducedType) {
@@ -5354,34 +5358,34 @@ module ts {
5354
5358
if (prototypeProperty) {
5355
5359
let targetType = getTypeOfSymbol(prototypeProperty);
5356
5360
if (targetType !== anyType) {
5357
- // Narrow to target type if it is a subtype of current type
5361
+ // Narrow to the target type if it's a subtype of the current type
5358
5362
if (isTypeSubtypeOf(targetType, type)) {
5359
5363
return targetType;
5360
5364
}
5361
- // If current type is a union type, remove all constituents that aren't subtypes of target type
5365
+ // If the current type is a union type, remove all constituents that aren't subtypes of the target.
5362
5366
if (type.flags & TypeFlags.Union) {
5363
- return getUnionType(filter(( <UnionType>type).types, t => isTypeSubtypeOf(t, targetType)) );
5367
+ return getUnionTypeOfSubtypeConstituents( <UnionType>type, targetType);
5364
5368
}
5365
5369
}
5366
5370
}
5367
5371
// Target type is type of constructor signiture
5368
- let constructSignitures : Signature[];
5372
+ let constructSignatures : Signature[];
5369
5373
if (rightType.flags & TypeFlags.Interface) {
5370
- constructSignitures = (<InterfaceTypeWithDeclaredMembers>rightType).declaredConstructSignatures;
5374
+ constructSignatures = (<InterfaceTypeWithDeclaredMembers>rightType).declaredConstructSignatures;
5375
+ } else if (rightType.flags & TypeFlags.Anonymous) {
5376
+ constructSignatures = (<ResolvedType>rightType).constructSignatures;
5371
5377
}
5372
- if (rightType.flags & TypeFlags.Anonymous) {
5373
- constructSignitures = (<ResolvedType>rightType).constructSignatures;
5374
- }
5375
- if (constructSignitures) {
5376
- let instanceType = getUnionType(map(constructSignitures, constructSignature => {
5378
+
5379
+ if (constructSignatures) {
5380
+ let instanceType = getUnionType(map(constructSignatures, constructSignature => {
5377
5381
if (constructSignature.typeParameters && constructSignature.typeParameters.length !== 0) {
5378
5382
constructSignature = instantiateSignature(constructSignature, createTypeMapper(constructSignature.typeParameters, map(constructSignature.typeParameters, _ => anyType)), true)
5379
5383
}
5380
5384
return constructSignature.resolvedReturnType;
5381
5385
}));
5382
5386
// Pickup type from union types
5383
5387
if (type.flags & TypeFlags.Union) {
5384
- return getUnionType(filter(( <UnionType>type).types, t => isTypeSubtypeOf(t, instanceType)) );
5388
+ return getUnionTypeOfSubtypeConstituents( <UnionType>type, instanceType);
5385
5389
}
5386
5390
return instanceType;
5387
5391
}
0 commit comments