@@ -8017,7 +8017,7 @@ namespace ts {
8017
8017
8018
8018
function cloneTypeMapper(mapper: TypeMapper): TypeMapper {
8019
8019
return mapper && isInferenceContext(mapper) ?
8020
- createInferenceContext(mapper.signature, mapper.flags | InferenceFlags.NoDefault, mapper.inferences) :
8020
+ createInferenceContext(mapper.signature, mapper.flags | InferenceFlags.NoDefault, mapper.compareTypes, mapper. inferences) :
8021
8021
mapper;
8022
8022
}
8023
8023
@@ -8458,7 +8458,7 @@ namespace ts {
8458
8458
ignoreReturnTypes: boolean,
8459
8459
reportErrors: boolean,
8460
8460
errorReporter: ErrorReporter,
8461
- compareTypes: (s: Type, t: Type, reportErrors?: boolean) => Ternary ): Ternary {
8461
+ compareTypes: TypeComparer ): Ternary {
8462
8462
// TODO (drosen): De-duplicate code between related functions.
8463
8463
if (source === target) {
8464
8464
return Ternary.True;
@@ -8468,7 +8468,7 @@ namespace ts {
8468
8468
}
8469
8469
8470
8470
if (source.typeParameters) {
8471
- source = instantiateSignatureInContextOf(source, target);
8471
+ source = instantiateSignatureInContextOf(source, target, /*contextualMapper*/ undefined, compareTypes );
8472
8472
}
8473
8473
8474
8474
let result = Ternary.True;
@@ -10216,13 +10216,14 @@ namespace ts {
10216
10216
}
10217
10217
}
10218
10218
10219
- function createInferenceContext(signature: Signature, flags: InferenceFlags, baseInferences?: InferenceInfo[]): InferenceContext {
10219
+ function createInferenceContext(signature: Signature, flags: InferenceFlags, compareTypes?: TypeComparer, baseInferences?: InferenceInfo[]): InferenceContext {
10220
10220
const inferences = baseInferences ? map(baseInferences, cloneInferenceInfo) : map(signature.typeParameters, createInferenceInfo);
10221
10221
const context = mapper as InferenceContext;
10222
10222
context.mappedTypes = signature.typeParameters;
10223
10223
context.signature = signature;
10224
10224
context.inferences = inferences;
10225
10225
context.flags = flags;
10226
+ context.compareTypes = compareTypes || compareTypesAssignable;
10226
10227
return context;
10227
10228
10228
10229
function mapper(t: Type): Type {
@@ -10670,7 +10671,7 @@ namespace ts {
10670
10671
const constraint = getConstraintOfTypeParameter(context.signature.typeParameters[index]);
10671
10672
if (constraint) {
10672
10673
const instantiatedConstraint = instantiateType(constraint, context);
10673
- if (!isTypeAssignableTo (inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
10674
+ if (!context.compareTypes (inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) {
10674
10675
inference.inferredType = inferredType = instantiatedConstraint;
10675
10676
}
10676
10677
}
@@ -15071,8 +15072,8 @@ namespace ts {
15071
15072
}
15072
15073
15073
15074
// Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec)
15074
- function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper?: TypeMapper): Signature {
15075
- const context = createInferenceContext(signature, InferenceFlags.InferUnionTypes);
15075
+ function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper?: TypeMapper, compareTypes?: TypeComparer ): Signature {
15076
+ const context = createInferenceContext(signature, InferenceFlags.InferUnionTypes, compareTypes );
15076
15077
forEachMatchingParameterType(contextualSignature, signature, (source, target) => {
15077
15078
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
15078
15079
inferTypes(context.inferences, instantiateType(source, contextualMapper || identityMapper), target);
0 commit comments