Skip to content

Commit 3157a76

Browse files
committed
Also do contravariant parameter type inferences
1 parent d6389af commit 3157a76

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33856,7 +33856,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3385633856
const sourceSignature = mapper ? instantiateSignature(contextualSignature, mapper) : contextualSignature;
3385733857
applyToParameterTypes(sourceSignature, signature, (source, target) => {
3385833858
// Type parameters from outer context referenced by source type are fixed by instantiation of the source type
33859-
inferTypes(context.inferences, source, target);
33859+
inferTypes(context.inferences, source, target, /*priority*/ undefined, /*contravariant*/ strictFunctionTypes);
3386033860
});
3386133861
if (!inferenceContext) {
3386233862
applyToReturnTypes(contextualSignature, signature, (source, target) => {

tests/baselines/reference/callbackAssignabilityErrorMessage.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
callbackAssignabilityErrorMessage.ts(31,1): error TS2322: Type 'Source1' is not assignable to type 'Target'.
2-
The types returned by 'map(...)' are incompatible between these types.
3-
Type '(T | undefined)[]' is not assignable to type 'T[]'.
2+
Types of property 'map' are incompatible.
3+
Types of parameters 'callbackfn' and 'callbackfn' are incompatible.
44
Type 'T | undefined' is not assignable to type 'T'.
55
'T' could be instantiated with an arbitrary type which could be unrelated to 'T | undefined'.
66

@@ -39,7 +39,7 @@ callbackAssignabilityErrorMessage.ts(31,1): error TS2322: Type 'Source1' is not
3939
t = s1; // Bad: instantiates `S` with `T | undefined`, fails `map` return type assignability
4040
~
4141
!!! error TS2322: Type 'Source1' is not assignable to type 'Target'.
42-
!!! error TS2322: The types returned by 'map(...)' are incompatible between these types.
43-
!!! error TS2322: Type '(T | undefined)[]' is not assignable to type 'T[]'.
42+
!!! error TS2322: Types of property 'map' are incompatible.
43+
!!! error TS2322: Types of parameters 'callbackfn' and 'callbackfn' are incompatible.
4444
!!! error TS2322: Type 'T | undefined' is not assignable to type 'T'.
4545
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'T | undefined'.

tests/baselines/reference/mappedTypeInferenceFromApparentType.errors.txt

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
mappedTypeInferenceFromApparentType.ts(10,1): error TS2322: Type 'foo' is not assignable to type 'bar'.
22
Types of parameters 'target' and 'source' are incompatible.
3-
Type '{ [K in keyof U]: Obj[K]; }' is not assignable to type '{ [K in keyof U]: U[K]; }'.
4-
Type 'Obj[K]' is not assignable to type 'U[K]'.
5-
Type 'Obj' is not assignable to type 'U'.
6-
'U' could be instantiated with an arbitrary type which could be unrelated to 'Obj'.
3+
Type '{ [K in keyof U]: Obj[K]; }' is not assignable to type '{ [x: string]: number; }'.
4+
Index signature for type 'string' is missing in type 'number[]'.
75

86

97
==== mappedTypeInferenceFromApparentType.ts (1 errors) ====
@@ -20,7 +18,5 @@ mappedTypeInferenceFromApparentType.ts(10,1): error TS2322: Type 'foo' is not as
2018
~
2119
!!! error TS2322: Type 'foo' is not assignable to type 'bar'.
2220
!!! error TS2322: Types of parameters 'target' and 'source' are incompatible.
23-
!!! error TS2322: Type '{ [K in keyof U]: Obj[K]; }' is not assignable to type '{ [K in keyof U]: U[K]; }'.
24-
!!! error TS2322: Type 'Obj[K]' is not assignable to type 'U[K]'.
25-
!!! error TS2322: Type 'Obj' is not assignable to type 'U'.
26-
!!! error TS2322: 'U' could be instantiated with an arbitrary type which could be unrelated to 'Obj'.
21+
!!! error TS2322: Type '{ [K in keyof U]: Obj[K]; }' is not assignable to type '{ [x: string]: number; }'.
22+
!!! error TS2322: Index signature for type 'string' is missing in type 'number[]'.

0 commit comments

Comments
 (0)