Skip to content

Commit ee87cf4

Browse files
authored
Print the correct type in the top level chain as the message indicates (#21127)
1 parent ef5b171 commit ee87cf4

33 files changed

+165
-160
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23005,7 +23005,7 @@ namespace ts {
2300523005
Diagnostics.Property_0_in_type_1_is_not_assignable_to_the_same_property_in_base_type_2,
2300623006
unescapeLeadingUnderscores(declaredProp.escapedName),
2300723007
typeToString(typeWithThis),
23008-
typeToString(getTypeOfSymbol(baseProp))
23008+
typeToString(baseWithThis)
2300923009
);
2301023010
if (!checkTypeAssignableTo(getTypeOfSymbol(prop), getTypeOfSymbol(baseProp), member.name || member, /*message*/ undefined, rootChain)) {
2301123011
issuedMemberError = true;

tests/baselines/reference/abstractPropertyNegative.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstra
77
tests/cases/compiler/abstractPropertyNegative.ts(15,5): error TS1244: Abstract methods can only appear within an abstract class.
88
tests/cases/compiler/abstractPropertyNegative.ts(16,37): error TS1005: '{' expected.
99
tests/cases/compiler/abstractPropertyNegative.ts(19,3): error TS2540: Cannot assign to 'ro' because it is a constant or a read-only property.
10-
tests/cases/compiler/abstractPropertyNegative.ts(25,5): error TS2416: Property 'num' in type 'WrongTypePropertyImpl' is not assignable to the same property in base type 'number'.
10+
tests/cases/compiler/abstractPropertyNegative.ts(25,5): error TS2416: Property 'num' in type 'WrongTypePropertyImpl' is not assignable to the same property in base type 'WrongTypeProperty'.
1111
Type 'string' is not assignable to type 'number'.
12-
tests/cases/compiler/abstractPropertyNegative.ts(31,9): error TS2416: Property 'num' in type 'WrongTypeAccessorImpl' is not assignable to the same property in base type 'number'.
12+
tests/cases/compiler/abstractPropertyNegative.ts(31,9): error TS2416: Property 'num' in type 'WrongTypeAccessorImpl' is not assignable to the same property in base type 'WrongTypeAccessor'.
1313
Type 'string' is not assignable to type 'number'.
14-
tests/cases/compiler/abstractPropertyNegative.ts(34,5): error TS2416: Property 'num' in type 'WrongTypeAccessorImpl2' is not assignable to the same property in base type 'number'.
14+
tests/cases/compiler/abstractPropertyNegative.ts(34,5): error TS2416: Property 'num' in type 'WrongTypeAccessorImpl2' is not assignable to the same property in base type 'WrongTypeAccessor'.
1515
Type 'string' is not assignable to type 'number'.
1616
tests/cases/compiler/abstractPropertyNegative.ts(38,18): error TS2676: Accessors must both be abstract or non-abstract.
1717
tests/cases/compiler/abstractPropertyNegative.ts(39,9): error TS2676: Accessors must both be abstract or non-abstract.
@@ -64,7 +64,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors
6464
class WrongTypePropertyImpl extends WrongTypeProperty {
6565
num = "nope, wrong";
6666
~~~
67-
!!! error TS2416: Property 'num' in type 'WrongTypePropertyImpl' is not assignable to the same property in base type 'number'.
67+
!!! error TS2416: Property 'num' in type 'WrongTypePropertyImpl' is not assignable to the same property in base type 'WrongTypeProperty'.
6868
!!! error TS2416: Type 'string' is not assignable to type 'number'.
6969
}
7070
abstract class WrongTypeAccessor {
@@ -73,13 +73,13 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors
7373
class WrongTypeAccessorImpl extends WrongTypeAccessor {
7474
get num() { return "nope, wrong"; }
7575
~~~
76-
!!! error TS2416: Property 'num' in type 'WrongTypeAccessorImpl' is not assignable to the same property in base type 'number'.
76+
!!! error TS2416: Property 'num' in type 'WrongTypeAccessorImpl' is not assignable to the same property in base type 'WrongTypeAccessor'.
7777
!!! error TS2416: Type 'string' is not assignable to type 'number'.
7878
}
7979
class WrongTypeAccessorImpl2 extends WrongTypeAccessor {
8080
num = "nope, wrong";
8181
~~~
82-
!!! error TS2416: Property 'num' in type 'WrongTypeAccessorImpl2' is not assignable to the same property in base type 'number'.
82+
!!! error TS2416: Property 'num' in type 'WrongTypeAccessorImpl2' is not assignable to the same property in base type 'WrongTypeAccessor'.
8383
!!! error TS2416: Type 'string' is not assignable to type 'number'.
8484
}
8585

tests/baselines/reference/apparentTypeSubtyping.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'string'.
1+
tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'Base<string>'.
22
Type 'String' is not assignable to type 'string'.
33
'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
44

@@ -15,7 +15,7 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtypi
1515
class Derived<U> extends Base<string> { // error
1616
x: String;
1717
~
18-
!!! error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'string'.
18+
!!! error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'Base<string>'.
1919
!!! error TS2416: Type 'String' is not assignable to type 'string'.
2020
!!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
2121
}

tests/baselines/reference/apparentTypeSupertype.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(10,5): error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'string'.
1+
tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(10,5): error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'Base'.
22
Type 'U' is not assignable to type 'string'.
33
Type 'String' is not assignable to type 'string'.
44
'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
@@ -16,7 +16,7 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty
1616
class Derived<U extends String> extends Base { // error
1717
x: U;
1818
~
19-
!!! error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'string'.
19+
!!! error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'Base'.
2020
!!! error TS2416: Type 'U' is not assignable to type 'string'.
2121
!!! error TS2416: Type 'String' is not assignable to type 'string'.
2222
!!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.

tests/baselines/reference/baseClassImprovedMismatchErrors.errors.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2416: Property 'n' in type 'Derived' is not assignable to the same property in base type 'string | Base'.
1+
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2416: Property 'n' in type 'Derived' is not assignable to the same property in base type 'Base'.
22
Type 'string | Derived' is not assignable to type 'string | Base'.
33
Type 'Derived' is not assignable to type 'string | Base'.
44
Type 'Derived' is not assignable to type 'Base'.
55
Types of property 'n' are incompatible.
66
Type 'string | Derived' is not assignable to type 'string | Base'.
77
Type 'Derived' is not assignable to type 'string | Base'.
88
Type 'Derived' is not assignable to type 'Base'.
9-
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(9,5): error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type '() => number'.
9+
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(9,5): error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'.
1010
Type '() => string | number' is not assignable to type '() => number'.
1111
Type 'string | number' is not assignable to type 'number'.
1212
Type 'string' is not assignable to type 'number'.
13-
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(14,5): error TS2416: Property 'n' in type 'DerivedInterface' is not assignable to the same property in base type 'string | Base'.
13+
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(14,5): error TS2416: Property 'n' in type 'DerivedInterface' is not assignable to the same property in base type 'Base'.
1414
Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
1515
Type 'DerivedInterface' is not assignable to type 'string | Base'.
1616
Type 'DerivedInterface' is not assignable to type 'Base'.
1717
Types of property 'n' are incompatible.
1818
Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
1919
Type 'DerivedInterface' is not assignable to type 'string | Base'.
2020
Type 'DerivedInterface' is not assignable to type 'Base'.
21-
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Property 'fn' in type 'DerivedInterface' is not assignable to the same property in base type '() => number'.
21+
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Property 'fn' in type 'DerivedInterface' is not assignable to the same property in base type 'Base'.
2222
Type '() => string | number' is not assignable to type '() => number'.
2323
Type 'string | number' is not assignable to type 'number'.
2424
Type 'string' is not assignable to type 'number'.
@@ -34,7 +34,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro
3434
class Derived extends Base {
3535
n: Derived | string;
3636
~
37-
!!! error TS2416: Property 'n' in type 'Derived' is not assignable to the same property in base type 'string | Base'.
37+
!!! error TS2416: Property 'n' in type 'Derived' is not assignable to the same property in base type 'Base'.
3838
!!! error TS2416: Type 'string | Derived' is not assignable to type 'string | Base'.
3939
!!! error TS2416: Type 'Derived' is not assignable to type 'string | Base'.
4040
!!! error TS2416: Type 'Derived' is not assignable to type 'Base'.
@@ -44,7 +44,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro
4444
!!! error TS2416: Type 'Derived' is not assignable to type 'Base'.
4545
fn() {
4646
~~
47-
!!! error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type '() => number'.
47+
!!! error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'.
4848
!!! error TS2416: Type '() => string | number' is not assignable to type '() => number'.
4949
!!! error TS2416: Type 'string | number' is not assignable to type 'number'.
5050
!!! error TS2416: Type 'string' is not assignable to type 'number'.
@@ -54,7 +54,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro
5454
class DerivedInterface implements Base {
5555
n: DerivedInterface | string;
5656
~
57-
!!! error TS2416: Property 'n' in type 'DerivedInterface' is not assignable to the same property in base type 'string | Base'.
57+
!!! error TS2416: Property 'n' in type 'DerivedInterface' is not assignable to the same property in base type 'Base'.
5858
!!! error TS2416: Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
5959
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'string | Base'.
6060
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'Base'.
@@ -64,7 +64,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro
6464
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'Base'.
6565
fn() {
6666
~~
67-
!!! error TS2416: Property 'fn' in type 'DerivedInterface' is not assignable to the same property in base type '() => number'.
67+
!!! error TS2416: Property 'fn' in type 'DerivedInterface' is not assignable to the same property in base type 'Base'.
6868
!!! error TS2416: Type '() => string | number' is not assignable to type '() => number'.
6969
!!! error TS2416: Type 'string | number' is not assignable to type 'number'.
7070
!!! error TS2416: Type 'string' is not assignable to type 'number'.

tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type '{ bar: string; }'.
1+
tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type 'Base<{ bar: string; }>'.
22
Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'.
33
Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'.
44

@@ -17,7 +17,7 @@ tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/cla
1717
class Derived2 extends Base<{ bar: string; }> {
1818
foo: {
1919
~~~
20-
!!! error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type '{ bar: string; }'.
20+
!!! error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type 'Base<{ bar: string; }>'.
2121
!!! error TS2416: Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'.
2222
!!! error TS2416: Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'.
2323
bar?: string; // error

tests/baselines/reference/derivedClassFunctionOverridesBaseClassAccessor.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
22
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
3-
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor.ts(11,5): error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'number'.
3+
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor.ts(11,5): error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'Base'.
44
Type '() => number' is not assignable to type 'number'.
55
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor.ts(11,5): error TS2426: Class 'Base' defines instance member accessor 'x', but extended class 'Derived' defines it as instance member function.
66

@@ -22,7 +22,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFun
2222
class Derived extends Base {
2323
x() {
2424
~
25-
!!! error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'number'.
25+
!!! error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'Base'.
2626
!!! error TS2416: Type '() => number' is not assignable to type 'number'.
2727
~
2828
!!! error TS2426: Class 'Base' defines instance member accessor 'x', but extended class 'Derived' defines it as instance member function.

tests/baselines/reference/destructuringParameterDeclaration2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
3535
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(46,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
3636
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(47,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
3737
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(56,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
38-
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(57,5): error TS2416: Property 'd4' in type 'C4' is not assignable to the same property in base type '({ x, y, z }?: { x: any; y: any; z: any; }) => any'.
38+
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(57,5): error TS2416: Property 'd4' in type 'C4' is not assignable to the same property in base type 'F2'.
3939
Type '({ x, y, c }: { x: any; y: any; c: any; }) => void' is not assignable to type '({ x, y, z }?: { x: any; y: any; z: any; }) => any'.
4040
Types of parameters '__0' and '__0' are incompatible.
4141
Type '{ x: any; y: any; z: any; }' is not assignable to type '{ x: any; y: any; c: any; }'.
@@ -159,7 +159,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
159159
!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
160160
d4({x, y, c}) { }
161161
~~
162-
!!! error TS2416: Property 'd4' in type 'C4' is not assignable to the same property in base type '({ x, y, z }?: { x: any; y: any; z: any; }) => any'.
162+
!!! error TS2416: Property 'd4' in type 'C4' is not assignable to the same property in base type 'F2'.
163163
!!! error TS2416: Type '({ x, y, c }: { x: any; y: any; c: any; }) => void' is not assignable to type '({ x, y, z }?: { x: any; y: any; z: any; }) => any'.
164164
!!! error TS2416: Types of parameters '__0' and '__0' are incompatible.
165165
!!! error TS2416: Type '{ x: any; y: any; z: any; }' is not assignable to type '{ x: any; y: any; c: any; }'.

tests/baselines/reference/elaboratedErrors.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/elaboratedErrors.ts(11,3): error TS2416: Property 'read' in type 'WorkerFS' is not assignable to the same property in base type 'number'.
1+
tests/cases/compiler/elaboratedErrors.ts(11,3): error TS2416: Property 'read' in type 'WorkerFS' is not assignable to the same property in base type 'FileSystem'.
22
Type 'string' is not assignable to type 'number'.
33
tests/cases/compiler/elaboratedErrors.ts(20,1): error TS2322: Type 'Beta' is not assignable to type 'Alpha'.
44
Property 'x' is missing in type 'Beta'.
@@ -21,7 +21,7 @@ tests/cases/compiler/elaboratedErrors.ts(25,1): error TS2322: Type 'Alpha' is no
2121
class WorkerFS implements FileSystem {
2222
read: string;
2323
~~~~
24-
!!! error TS2416: Property 'read' in type 'WorkerFS' is not assignable to the same property in base type 'number'.
24+
!!! error TS2416: Property 'read' in type 'WorkerFS' is not assignable to the same property in base type 'FileSystem'.
2525
!!! error TS2416: Type 'string' is not assignable to type 'number'.
2626
}
2727

tests/baselines/reference/genericImplements.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/genericImplements.ts(9,5): error TS2416: Property 'f' in type 'X' is not assignable to the same property in base type '<T extends A>() => T'.
1+
tests/cases/compiler/genericImplements.ts(9,5): error TS2416: Property 'f' in type 'X' is not assignable to the same property in base type 'I'.
22
Type '<T extends B>() => T' is not assignable to type '<T extends A>() => T'.
33
Type 'B' is not assignable to type 'T'.
44

@@ -14,7 +14,7 @@ tests/cases/compiler/genericImplements.ts(9,5): error TS2416: Property 'f' in ty
1414
class X implements I {
1515
f<T extends B>(): T { return undefined; }
1616
~
17-
!!! error TS2416: Property 'f' in type 'X' is not assignable to the same property in base type '<T extends A>() => T'.
17+
!!! error TS2416: Property 'f' in type 'X' is not assignable to the same property in base type 'I'.
1818
!!! error TS2416: Type '<T extends B>() => T' is not assignable to type '<T extends A>() => T'.
1919
!!! error TS2416: Type 'B' is not assignable to type 'T'.
2020
} // { f: () => { b; } }

0 commit comments

Comments
 (0)