@@ -16531,36 +16531,31 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
16531
16531
}
16532
16532
16533
16533
function getUnionOrIntersectionTypePredicate(signatures: readonly Signature[], kind: TypeFlags | undefined): TypePredicate | undefined {
16534
- let first : TypePredicate | undefined;
16534
+ let last : TypePredicate | undefined;
16535
16535
const types: Type[] = [];
16536
16536
for (const sig of signatures) {
16537
16537
const pred = getTypePredicateOfSignature(sig);
16538
- if (!pred || pred.kind === TypePredicateKind.AssertsThis || pred.kind === TypePredicateKind.AssertsIdentifier) {
16539
- if (kind !== TypeFlags.Intersection) {
16540
- continue;
16541
- }
16542
- else {
16543
- return; // intersections demand all members be type predicates for the result to have a predicate
16544
- }
16545
- }
16546
-
16547
- if (first) {
16548
- if (!typePredicateKindsMatch(first, pred)) {
16549
- // No common type predicate.
16538
+ if (pred) {
16539
+ // Constituent type predicates must all have matching kinds. We don't create composite type predicates for assertions.
16540
+ if (pred.kind !== TypePredicateKind.This && pred.kind !== TypePredicateKind.Identifier || last && !typePredicateKindsMatch(last, pred)) {
16550
16541
return undefined;
16551
16542
}
16543
+ last = pred;
16544
+ types.push(pred.type);
16552
16545
}
16553
16546
else {
16554
- first = pred;
16547
+ // In composite union signatures we permit and ignore signatures with a return type `false`.
16548
+ const returnType = kind !== TypeFlags.Intersection ? getReturnTypeOfSignature(sig) : undefined;
16549
+ if (returnType !== falseType && returnType !== regularFalseType) {
16550
+ return undefined;
16551
+ }
16555
16552
}
16556
- types.push(pred.type);
16557
16553
}
16558
- if (!first) {
16559
- // No signatures had a type predicate.
16554
+ if (!last) {
16560
16555
return undefined;
16561
16556
}
16562
16557
const compositeType = getUnionOrIntersectionType(types, kind);
16563
- return createTypePredicate(first .kind, first .parameterName, first .parameterIndex, compositeType);
16558
+ return createTypePredicate(last .kind, last .parameterName, last .parameterIndex, compositeType);
16564
16559
}
16565
16560
16566
16561
function typePredicateKindsMatch(a: TypePredicate, b: TypePredicate): boolean {
0 commit comments