Skip to content

Commit ecf20fe

Browse files
committed
Only report unmeasurable when both covariant and contravariant comparisons are unknown
1 parent 0e86a8f commit ecf20fe

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19763,7 +19763,7 @@ namespace ts {
1976319763
const covariant = isTypeRelatedToWorker(typeWithSub, typeWithSuper, assignableRelation);
1976419764
const contravariant = isTypeRelatedToWorker(typeWithSuper, typeWithSub, assignableRelation);
1976519765
let variance = 0;
19766-
if (covariant === Ternary.Unknown || contravariant === Ternary.Unknown) {
19766+
if (covariant === Ternary.Unknown && contravariant === Ternary.Unknown) {
1976719767
unmeasurable = true;
1976819768
}
1976919769
else {

tests/baselines/reference/checkOrderDependenceGenericAssignability.errors.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
tests/cases/compiler/checkOrderDependenceGenericAssignability.ts(46,7): error TS2322: Type 'Parent<unknown>' is not assignable to type 'Parent<string>'.
2-
The types of 'child.a' are incompatible between these types.
3-
Type 'unknown' is not assignable to type 'string'.
2+
Types of property 'child' are incompatible.
3+
Type 'Child<unknown, unknown>' is not assignable to type 'Child<string, unknown>'.
4+
Type 'unknown' is not assignable to type 'string'.
45

56

67
==== tests/cases/compiler/checkOrderDependenceGenericAssignability.ts (1 errors) ====
@@ -52,6 +53,7 @@ tests/cases/compiler/checkOrderDependenceGenericAssignability.ts(46,7): error TS
5253
const notString: Parent<string> = pu;
5354
~~~~~~~~~
5455
!!! error TS2322: Type 'Parent<unknown>' is not assignable to type 'Parent<string>'.
55-
!!! error TS2322: The types of 'child.a' are incompatible between these types.
56-
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
56+
!!! error TS2322: Types of property 'child' are incompatible.
57+
!!! error TS2322: Type 'Child<unknown, unknown>' is not assignable to type 'Child<string, unknown>'.
58+
!!! error TS2322: Type 'unknown' is not assignable to type 'string'.
5759

0 commit comments

Comments
 (0)