mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 21:07:52 -05:00
Add early bail out for call expressions that are never type predicates
This commit is contained in:
@@ -8981,6 +8981,28 @@ namespace ts {
|
||||
return isLengthPushOrUnshift || isElementAssignment;
|
||||
}
|
||||
|
||||
function maybeTypePredicateCall(node: CallExpression) {
|
||||
const links = getNodeLinks(node);
|
||||
if (links.maybeTypePredicate === undefined) {
|
||||
links.maybeTypePredicate = getMaybeTypePredicate(node);
|
||||
}
|
||||
return links.maybeTypePredicate;
|
||||
}
|
||||
|
||||
function getMaybeTypePredicate(node: CallExpression) {
|
||||
if (node.expression.kind !== SyntaxKind.SuperKeyword) {
|
||||
const funcType = checkNonNullExpression(node.expression);
|
||||
if (funcType !== silentNeverType) {
|
||||
const apparentType = getApparentType(funcType);
|
||||
if (apparentType !== unknownType) {
|
||||
const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
|
||||
return !!forEach(callSignatures, sig => sig.typePredicate);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getFlowTypeOfReference(reference: Node, declaredType: Type, assumeInitialized: boolean, flowContainer: Node) {
|
||||
let key: string;
|
||||
if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) {
|
||||
@@ -9495,7 +9517,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function narrowTypeByTypePredicate(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
|
||||
if (!hasMatchingArgument(callExpression, reference)) {
|
||||
if (!hasMatchingArgument(callExpression, reference) || !maybeTypePredicateCall(callExpression)) {
|
||||
return type;
|
||||
}
|
||||
const signature = getResolvedSignature(callExpression);
|
||||
|
||||
@@ -2668,6 +2668,7 @@ namespace ts {
|
||||
resolvedSignature?: Signature; // Cached signature of signature node or call expression
|
||||
resolvedSymbol?: Symbol; // Cached name resolution result
|
||||
resolvedIndexInfo?: IndexInfo; // Cached indexing info resolution result
|
||||
maybeTypePredicate?: boolean; // Cached check whether call expression might reference a type predicate
|
||||
enumMemberValue?: number; // Constant value of enum member
|
||||
isVisible?: boolean; // Is this node visible
|
||||
hasReportedStatementInAmbientContext?: boolean; // Cache boolean if we report statements in ambient context
|
||||
|
||||
Reference in New Issue
Block a user