File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -8548,10 +8548,6 @@ namespace ts {
8548
8548
}
8549
8549
return type;
8550
8550
}
8551
- // We never narrow type any in an instanceof guard
8552
- if (isTypeAny(type)) {
8553
- return type;
8554
- }
8555
8551
8556
8552
// Check that right operand is a function type with a prototype property
8557
8553
const rightType = checkExpression(expr.right);
@@ -8569,6 +8565,11 @@ namespace ts {
8569
8565
}
8570
8566
}
8571
8567
8568
+ // Don't narrow from 'any' if the target type is exactly 'Object' or 'Function'
8569
+ if (isTypeAny(type) && (targetType === globalObjectType || targetType === globalFunctionType)) {
8570
+ return type;
8571
+ }
8572
+
8572
8573
if (!targetType) {
8573
8574
// Target type is type of construct signature
8574
8575
let constructSignatures: Signature[];
@@ -8615,14 +8616,20 @@ namespace ts {
8615
8616
}
8616
8617
8617
8618
function narrowTypeByTypePredicate(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
8618
- if (type.flags & TypeFlags.Any || !hasMatchingArgument(callExpression, reference)) {
8619
+ if (!hasMatchingArgument(callExpression, reference)) {
8619
8620
return type;
8620
8621
}
8621
8622
const signature = getResolvedSignature(callExpression);
8622
8623
const predicate = signature.typePredicate;
8623
8624
if (!predicate) {
8624
8625
return type;
8625
8626
}
8627
+
8628
+ // Don't narrow from 'any' if the predicate type is exactly 'Object' or 'Function'
8629
+ if (isTypeAny(type) && (predicate.type === globalObjectType || predicate.type === globalFunctionType)) {
8630
+ return type;
8631
+ }
8632
+
8626
8633
if (isIdentifierTypePredicate(predicate)) {
8627
8634
const predicateArgument = callExpression.arguments[predicate.parameterIndex];
8628
8635
if (predicateArgument) {
You can’t perform that action at this time.
0 commit comments