From cedfd7e08b15d1e642169622ed4e0c76083bef2f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 24 Sep 2018 16:34:48 -0700 Subject: [PATCH] Fix 'x instanceof ctor' where type of ctor is Function --- src/compiler/checker.ts | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 691b994daae..7e9080164d0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15351,24 +15351,13 @@ namespace ts { } if (!targetType) { - // Target type is type of construct signature - let constructSignatures: ReadonlyArray | undefined; - if (getObjectFlags(rightType) & ObjectFlags.Interface) { - constructSignatures = resolveDeclaredMembers(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) {