Skip to content

Commit 880ccf0

Browse files
committed
PR feedback
1 parent ab10d50 commit 880ccf0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,6 +3599,10 @@ module ts {
35993599
return type;
36003600
}
36013601

3602+
function getUnionTypeOfSubtypeConstituents(source: UnionType, target: Type): Type {
3603+
return getUnionType(filter(source.types, t => isTypeSubtypeOf(t, target)));
3604+
}
3605+
36023606
function getReducedTypeOfUnionType(type: UnionType): Type {
36033607
// If union type was created without subtype reduction, perform the deferred reduction now
36043608
if (!type.reducedType) {
@@ -5354,34 +5358,34 @@ module ts {
53545358
if (prototypeProperty) {
53555359
let targetType = getTypeOfSymbol(prototypeProperty);
53565360
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
53585362
if (isTypeSubtypeOf(targetType, type)) {
53595363
return targetType;
53605364
}
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.
53625366
if (type.flags & TypeFlags.Union) {
5363-
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, targetType)));
5367+
return getUnionTypeOfSubtypeConstituents(<UnionType>type, targetType);
53645368
}
53655369
}
53665370
}
53675371
// Target type is type of constructor signiture
5368-
let constructSignitures: Signature[];
5372+
let constructSignatures: Signature[];
53695373
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;
53715377
}
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 => {
53775381
if (constructSignature.typeParameters && constructSignature.typeParameters.length !== 0) {
53785382
constructSignature = instantiateSignature(constructSignature, createTypeMapper(constructSignature.typeParameters, map(constructSignature.typeParameters, _ => anyType)), true)
53795383
}
53805384
return constructSignature.resolvedReturnType;
53815385
}));
53825386
// Pickup type from union types
53835387
if (type.flags & TypeFlags.Union) {
5384-
return getUnionType(filter((<UnionType>type).types, t => isTypeSubtypeOf(t, instanceType)));
5388+
return getUnionTypeOfSubtypeConstituents(<UnionType>type, instanceType);
53855389
}
53865390
return instanceType;
53875391
}

0 commit comments

Comments
 (0)