Skip to content

Commit bf1af7a

Browse files
committed
microsoft#25002 - changed error message
1 parent 9aa2468 commit bf1af7a

11 files changed

+47
-36
lines changed

lib/enu/diagnosticMessages.generated.json.lcg

+1-1
Original file line numberDiff line numberDiff line change
@@ -6323,7 +6323,7 @@
63236323
</Item>
63246324
<Item ItemId=";get_and_set_accessor_must_have_the_same_type_2380" ItemType="0" PsrId="306" Leaf="true">
63256325
<Str Cat="Text">
6326-
<Val><![CDATA['get' and 'set' accessor must have the same type '{0}', but this 'get' accessor has the type '{1}'.]]></Val>
6326+
<Val><![CDATA['get' and 'set' accessor must have the same type.]]></Val>
63276327
</Str>
63286328
<Disp Icon="Str" />
63296329
</Item>

lib/tsc.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2942,7 +2942,7 @@ var ts;
29422942
Constructors_for_derived_classes_must_contain_a_super_call: diag(2377, ts.DiagnosticCategory.Error, "Constructors_for_derived_classes_must_contain_a_super_call_2377", "Constructors for derived classes must contain a 'super' call."),
29432943
A_get_accessor_must_return_a_value: diag(2378, ts.DiagnosticCategory.Error, "A_get_accessor_must_return_a_value_2378", "A 'get' accessor must return a value."),
29442944
Getter_and_setter_accessors_do_not_agree_in_visibility: diag(2379, ts.DiagnosticCategory.Error, "Getter_and_setter_accessors_do_not_agree_in_visibility_2379", "Getter and setter accessors do not agree in visibility."),
2945-
get_and_set_accessor_must_have_the_same_type_0_but_this_get_accessor_has_the_type_1: diag(2380, ts.DiagnosticCategory.Error, "get_and_set_accessor_must_have_the_same_type_2380", "'get' and 'set' accessor must have the same type '{0}', but this 'get' accessor has the type '{1}'."),
2945+
get_and_set_accessor_must_have_the_same_type: diag(2380, ts.DiagnosticCategory.Error, "get_and_set_accessor_must_have_the_same_type_2380", "'get' and 'set' accessor must have the same type."),
29462946
A_signature_with_an_implementation_cannot_use_a_string_literal_type: diag(2381, ts.DiagnosticCategory.Error, "A_signature_with_an_implementation_cannot_use_a_string_literal_type_2381", "A signature with an implementation cannot use a string literal type."),
29472947
Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: diag(2382, ts.DiagnosticCategory.Error, "Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature_2382", "Specialized overload signature is not assignable to any non-specialized signature."),
29482948
Overload_signatures_must_all_be_exported_or_non_exported: diag(2383, ts.DiagnosticCategory.Error, "Overload_signatures_must_all_be_exported_or_non_exported_2383", "Overload signatures must all be exported or non-exported."),
@@ -3212,7 +3212,6 @@ var ts;
32123212
Class_name_cannot_be_Object_when_targeting_ES5_with_module_0: diag(2725, ts.DiagnosticCategory.Error, "Class_name_cannot_be_Object_when_targeting_ES5_with_module_0_2725", "Class name cannot be 'Object' when targeting ES5 with module {0}."),
32133213
Cannot_find_lib_definition_for_0: diag(2726, ts.DiagnosticCategory.Error, "Cannot_find_lib_definition_for_0_2726", "Cannot find lib definition for '{0}'."),
32143214
Cannot_find_lib_definition_for_0_Did_you_mean_1: diag(2727, ts.DiagnosticCategory.Error, "Cannot_find_lib_definition_for_0_Did_you_mean_1_2727", "Cannot find lib definition for '{0}'. Did you mean '{1}'?"),
3215-
The_respective_set_accessor_has_the_type_0: diag(2730, ts.DiagnosticCategory.Error, "The_respective_set_accessor_has_the_type_0_2730", "The respective 'set' accessor has the type '{0}'."),
32163215
Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
32173216
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
32183217
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),

src/compiler/checker.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -22062,14 +22062,11 @@ namespace ts {
2206222062
const firstType = getAnnotatedType(first);
2206322063
const secondType = getAnnotatedType(second);
2206422064
if (firstType && secondType && !isTypeIdenticalTo(firstType, secondType)) {
22065-
22066-
if(isGetAccessor(first)){
22067-
const typeNameFirstType = typeToString(firstType);
22068-
const typeNameSecondType = typeToString(secondType);
22065+
const typeNameFirstType = typeToString(firstType);
22066+
const typeNameSecondType = typeToString(secondType);
2206922067

22070-
const diagnostic: Diagnostic = error(first, message, typeNameSecondType, typeNameFirstType);
22071-
diagnostic.relatedInformation = [createDiagnosticForNode(first, Diagnostics.The_respective_set_accessor_has_the_type_0, typeNameSecondType)];
22072-
}
22068+
const diagnostic: Diagnostic = error(first, message, typeNameSecondType, typeNameFirstType);
22069+
addRelatedInfo(diagnostic, createDiagnosticForNode(first, Diagnostics.The_respective_set_accessor_has_the_type_0, typeNameSecondType));
2207322070
}
2207422071
}
2207522072

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,7 @@
24102410
"code": 2729
24112411
},
24122412
"The respective 'set' accessor has the type '{0}'.": {
2413-
"category": "Error",
2413+
"category": "Message",
24142414
"code": 2730
24152415
},
24162416

tests/baselines/reference/abstractPropertyNegative.errors.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/compiler/abstractPropertyNegative.ts(10,18): error TS2380: 'get' and 'set' accessor must have the same type.
2-
tests/cases/compiler/abstractPropertyNegative.ts(11,18): error TS2380: 'get' and 'set' accessor must have the same type.
1+
tests/cases/compiler/abstractPropertyNegative.ts(10,18): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'.
2+
tests/cases/compiler/abstractPropertyNegative.ts(11,18): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'.
33
tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'm' from class 'B'.
44
tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'mismatch' from class 'B'.
55
tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'prop' from class 'B'.
@@ -31,10 +31,12 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors
3131
abstract m(): string;
3232
abstract get mismatch(): string;
3333
~~~~~~~~
34-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
34+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'.
35+
!!! related TS2730 tests/cases/compiler/abstractPropertyNegative.ts:10:18: The respective 'set' accessor has the type 'number'.
3536
abstract set mismatch(val: number); // error, not same type
3637
~~~~~~~~
37-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
38+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'.
39+
!!! related TS2730 tests/cases/compiler/abstractPropertyNegative.ts:11:18: The respective 'set' accessor has the type 'string'.
3840
}
3941
class C extends B {
4042
~

tests/baselines/reference/api/tsserverlibrary.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5156,7 +5156,7 @@ declare namespace ts {
51565156
Constructors_for_derived_classes_must_contain_a_super_call: DiagnosticMessage;
51575157
A_get_accessor_must_return_a_value: DiagnosticMessage;
51585158
Getter_and_setter_accessors_do_not_agree_in_visibility: DiagnosticMessage;
5159-
get_and_set_accessor_must_have_the_same_type: DiagnosticMessage;
5159+
get_and_set_accessor_must_have_the_same_type_0_but_this_get_accessor_has_the_type_1: DiagnosticMessage;
51605160
A_signature_with_an_implementation_cannot_use_a_string_literal_type: DiagnosticMessage;
51615161
Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: DiagnosticMessage;
51625162
Overload_signatures_must_all_be_exported_or_non_exported: DiagnosticMessage;
@@ -5432,6 +5432,7 @@ declare namespace ts {
54325432
Cannot_find_lib_definition_for_0_Did_you_mean_1: DiagnosticMessage;
54335433
_0_was_declared_here: DiagnosticMessage;
54345434
Property_0_is_used_before_its_initialization: DiagnosticMessage;
5435+
The_respective_set_accessor_has_the_type_0: DiagnosticMessage;
54355436
Import_declaration_0_is_using_private_name_1: DiagnosticMessage;
54365437
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: DiagnosticMessage;
54375438
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: DiagnosticMessage;
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/compiler/getAndSetNotIdenticalType.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2-
tests/cases/compiler/getAndSetNotIdenticalType.ts(2,9): error TS2380: 'get' and 'set' accessor must have the same type.
2+
tests/cases/compiler/getAndSetNotIdenticalType.ts(2,9): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'.
33
tests/cases/compiler/getAndSetNotIdenticalType.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
4-
tests/cases/compiler/getAndSetNotIdenticalType.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type.
4+
tests/cases/compiler/getAndSetNotIdenticalType.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'.
55

66

77
==== tests/cases/compiler/getAndSetNotIdenticalType.ts (4 errors) ====
@@ -10,12 +10,14 @@ tests/cases/compiler/getAndSetNotIdenticalType.ts(5,9): error TS2380: 'get' and
1010
~
1111
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
1212
~
13-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
13+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'.
14+
!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType.ts:2:9: The respective 'set' accessor has the type 'string'.
1415
return 1;
1516
}
1617
set x(v: string) { }
1718
~
1819
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
1920
~
20-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
21+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'.
22+
!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType.ts:5:9: The respective 'set' accessor has the type 'number'.
2123
}

tests/baselines/reference/getAndSetNotIdenticalType2.errors.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/compiler/getAndSetNotIdenticalType2.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2-
tests/cases/compiler/getAndSetNotIdenticalType2.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type.
2+
tests/cases/compiler/getAndSetNotIdenticalType2.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'A<string>', but this 'get' accessor has the type 'A<T>'.
33
tests/cases/compiler/getAndSetNotIdenticalType2.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
4-
tests/cases/compiler/getAndSetNotIdenticalType2.ts(8,9): error TS2380: 'get' and 'set' accessor must have the same type.
4+
tests/cases/compiler/getAndSetNotIdenticalType2.ts(8,9): error TS2380: 'get' and 'set' accessor must have the same type 'A<T>', but this 'get' accessor has the type 'A<string>'.
55
tests/cases/compiler/getAndSetNotIdenticalType2.ts(9,9): error TS2322: Type 'A<string>' is not assignable to type 'A<T>'.
66
Type 'string' is not assignable to type 'T'.
77

@@ -15,14 +15,16 @@ tests/cases/compiler/getAndSetNotIdenticalType2.ts(9,9): error TS2322: Type 'A<s
1515
~
1616
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
1717
~
18-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
18+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'A<string>', but this 'get' accessor has the type 'A<T>'.
19+
!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType2.ts:5:9: The respective 'set' accessor has the type 'A<string>'.
1920
return this.data;
2021
}
2122
set x(v: A<string>) {
2223
~
2324
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2425
~
25-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
26+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'A<T>', but this 'get' accessor has the type 'A<string>'.
27+
!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType2.ts:8:9: The respective 'set' accessor has the type 'A<T>'.
2628
this.data = v;
2729
~~~~~~~~~
2830
!!! error TS2322: Type 'A<string>' is not assignable to type 'A<T>'.

tests/baselines/reference/getAndSetNotIdenticalType3.errors.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/compiler/getAndSetNotIdenticalType3.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2-
tests/cases/compiler/getAndSetNotIdenticalType3.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type.
2+
tests/cases/compiler/getAndSetNotIdenticalType3.ts(5,9): error TS2380: 'get' and 'set' accessor must have the same type 'A<string>', but this 'get' accessor has the type 'A<number>'.
33
tests/cases/compiler/getAndSetNotIdenticalType3.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
4-
tests/cases/compiler/getAndSetNotIdenticalType3.ts(8,9): error TS2380: 'get' and 'set' accessor must have the same type.
4+
tests/cases/compiler/getAndSetNotIdenticalType3.ts(8,9): error TS2380: 'get' and 'set' accessor must have the same type 'A<number>', but this 'get' accessor has the type 'A<string>'.
55
tests/cases/compiler/getAndSetNotIdenticalType3.ts(9,9): error TS2322: Type 'A<string>' is not assignable to type 'A<number>'.
66
Type 'string' is not assignable to type 'number'.
77

@@ -15,14 +15,16 @@ tests/cases/compiler/getAndSetNotIdenticalType3.ts(9,9): error TS2322: Type 'A<s
1515
~
1616
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
1717
~
18-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
18+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'A<string>', but this 'get' accessor has the type 'A<number>'.
19+
!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType3.ts:5:9: The respective 'set' accessor has the type 'A<string>'.
1920
return this.data;
2021
}
2122
set x(v: A<string>) {
2223
~
2324
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2425
~
25-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
26+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'A<number>', but this 'get' accessor has the type 'A<string>'.
27+
!!! related TS2730 tests/cases/compiler/getAndSetNotIdenticalType3.ts:8:9: The respective 'set' accessor has the type 'A<number>'.
2628
this.data = v;
2729
~~~~~~~~~
2830
!!! error TS2322: Type 'A<string>' is not assignable to type 'A<number>'.

tests/baselines/reference/objectLiteralErrors.errors.txt

+12-8
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(38,26)
7171
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,13): error TS2300: Duplicate identifier 'a'.
7272
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46): error TS1119: An object literal cannot have property and accessor with the same name.
7373
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(39,46): error TS2300: Duplicate identifier 'a'.
74-
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,16): error TS2380: 'get' and 'set' accessor must have the same type.
75-
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,47): error TS2380: 'get' and 'set' accessor must have the same type.
74+
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,16): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'.
75+
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(42,47): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'.
7676
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(43,22): error TS2322: Type '4' is not assignable to type 'string'.
77-
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16): error TS2380: 'get' and 'set' accessor must have the same type.
78-
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55): error TS2380: 'get' and 'set' accessor must have the same type.
77+
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16): error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'.
78+
tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55): error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'.
7979

8080

8181
==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (78 errors) ====
@@ -268,15 +268,19 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,55)
268268
// Get and set accessor with mismatched type annotations
269269
var g1 = { get a(): number { return 4; }, set a(n: string) { } };
270270
~
271-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
271+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'.
272+
!!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:42:16: The respective 'set' accessor has the type 'string'.
272273
~
273-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
274+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'.
275+
!!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:42:47: The respective 'set' accessor has the type 'number'.
274276
var g2 = { get a() { return 4; }, set a(n: string) { } };
275277
~~~~~~~~~
276278
!!! error TS2322: Type '4' is not assignable to type 'string'.
277279
var g3 = { get a(): number { return undefined; }, set a(n: string) { } };
278280
~
279-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
281+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'string', but this 'get' accessor has the type 'number'.
282+
!!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:44:16: The respective 'set' accessor has the type 'string'.
280283
~
281-
!!! error TS2380: 'get' and 'set' accessor must have the same type.
284+
!!! error TS2380: 'get' and 'set' accessor must have the same type 'number', but this 'get' accessor has the type 'string'.
285+
!!! related TS2730 tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts:44:55: The respective 'set' accessor has the type 'number'.
282286

0 commit comments

Comments
 (0)