@@ -10920,7 +10920,7 @@ namespace ts {
10920
10920
target: Signature,
10921
10921
ignoreReturnTypes: boolean): boolean {
10922
10922
return compareSignaturesRelated(source, target, CallbackCheck.None, ignoreReturnTypes, /*reportErrors*/ false,
10923
- /*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False;
10923
+ /*errorReporter*/ undefined, compareTypesAssignable, compareTypesIdentical ) !== Ternary.False;
10924
10924
}
10925
10925
10926
10926
type ErrorReporter = (message: DiagnosticMessage, arg0?: string, arg1?: string) => void;
@@ -10934,7 +10934,8 @@ namespace ts {
10934
10934
ignoreReturnTypes: boolean,
10935
10935
reportErrors: boolean,
10936
10936
errorReporter: ErrorReporter | undefined,
10937
- compareTypes: TypeComparer): Ternary {
10937
+ compareTypes: TypeComparer,
10938
+ localCompareTypesIdentical: TypeComparer): Ternary {
10938
10939
// TODO (drosen): De-duplicate code between related functions.
10939
10940
if (source === target) {
10940
10941
return Ternary.True;
@@ -11000,7 +11001,7 @@ namespace ts {
11000
11001
(getFalsyFlags(sourceType) & TypeFlags.Nullable) === (getFalsyFlags(targetType) & TypeFlags.Nullable);
11001
11002
const related = callbacks ?
11002
11003
// TODO: GH#18217 It will work if they're both `undefined`, but not if only one is
11003
- compareSignaturesRelated(targetSig!, sourceSig!, strictVariance ? CallbackCheck.Strict : CallbackCheck.Bivariant, /*ignoreReturnTypes*/ false, reportErrors, errorReporter, compareTypes) :
11004
+ compareSignaturesRelated(targetSig!, sourceSig!, strictVariance ? CallbackCheck.Strict : CallbackCheck.Bivariant, /*ignoreReturnTypes*/ false, reportErrors, errorReporter, compareTypes, localCompareTypesIdentical ) :
11004
11005
!callbackCheck && !strictVariance && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors);
11005
11006
if (!related) {
11006
11007
if (reportErrors) {
@@ -11027,7 +11028,7 @@ namespace ts {
11027
11028
if (targetTypePredicate) {
11028
11029
const sourceTypePredicate = getTypePredicateOfSignature(source);
11029
11030
if (sourceTypePredicate) {
11030
- result &= compareTypePredicateRelatedTo(sourceTypePredicate, targetTypePredicate, source.declaration!, target.declaration!, reportErrors, errorReporter, compareTypes ); // TODO: GH#18217
11031
+ result &= compareTypePredicateRelatedTo(sourceTypePredicate, targetTypePredicate, source.declaration!, target.declaration!, reportErrors, errorReporter, localCompareTypesIdentical ); // TODO: GH#18217
11031
11032
}
11032
11033
else if (isIdentifierTypePredicate(targetTypePredicate)) {
11033
11034
if (reportErrors) {
@@ -11056,7 +11057,7 @@ namespace ts {
11056
11057
targetDeclaration: SignatureDeclaration | JSDocSignature,
11057
11058
reportErrors: boolean,
11058
11059
errorReporter: ErrorReporter | undefined,
11059
- compareTypes : (s: Type, t: Type, reportErrors?: boolean) => Ternary): Ternary {
11060
+ localCompareTypesIdentical : (s: Type, t: Type, reportErrors?: boolean) => Ternary): Ternary {
11060
11061
if (source.kind !== target.kind) {
11061
11062
if (reportErrors) {
11062
11063
errorReporter!(Diagnostics.A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard);
@@ -11078,7 +11079,7 @@ namespace ts {
11078
11079
}
11079
11080
}
11080
11081
11081
- const related = compareTypes (source.type, target.type, reportErrors);
11082
+ const related = localCompareTypesIdentical (source.type, target.type, reportErrors);
11082
11083
if (related === Ternary.False && reportErrors) {
11083
11084
errorReporter!(Diagnostics.Type_predicate_0_is_not_assignable_to_1, typePredicateToString(source), typePredicateToString(target));
11084
11085
}
@@ -12355,7 +12356,11 @@ namespace ts {
12355
12356
*/
12356
12357
function signatureRelatedTo(source: Signature, target: Signature, erase: boolean, reportErrors: boolean): Ternary {
12357
12358
return compareSignaturesRelated(erase ? getErasedSignature(source) : source, erase ? getErasedSignature(target) : target,
12358
- CallbackCheck.None, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo);
12359
+ CallbackCheck.None, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo,
12360
+ // If we are already in an identity check, we need to use isRelatedTo to use the
12361
+ // existing recursion limiter rather than start a new one, which could allow us
12362
+ // to recurse infinitely through this code path.
12363
+ relation === identityRelation ? isRelatedTo : compareTypesIdentical);
12359
12364
}
12360
12365
12361
12366
function signaturesIdenticalTo(source: Type, target: Type, kind: SignatureKind): Ternary {
0 commit comments