Fix 'x instanceof ctor' where type of ctor is Function

This commit is contained in:
Anders Hejlsberg 2018-09-24 16:34:48 -07:00
parent e1c8dc2768
commit cedfd7e08b

View File

@ -15351,24 +15351,13 @@ namespace ts {
}
if (!targetType) {
// Target type is type of construct signature
let constructSignatures: ReadonlyArray<Signature> | undefined;
if (getObjectFlags(rightType) & ObjectFlags.Interface) {
constructSignatures = resolveDeclaredMembers(<InterfaceType>rightType).declaredConstructSignatures;
}
else if (getObjectFlags(rightType) & ObjectFlags.Anonymous) {
constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct);
}
if (constructSignatures && constructSignatures.length) {
targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature))));
}
const constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct);
targetType = constructSignatures && constructSignatures.length ?
getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))) :
emptyObjectType;
}
if (targetType) {
return getNarrowedType(type, targetType, assumeTrue, isTypeDerivedFrom);
}
return type;
return getNarrowedType(type, targetType, assumeTrue, isTypeDerivedFrom);
}
function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean, isRelated: (source: Type, target: Type) => boolean) {