Skip to content

Commit 51caec2

Browse files
committed
Implementation for issue microsoft#25002
1 parent a1746d4 commit 51caec2

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
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.]]></Val>
6326+
<Val><![CDATA['get' and 'set' accessor must have the same type, but this 'get' accessor has the type '{0}']]></Val>
63276327
</Str>
63286328
<Disp Icon="Str" />
63296329
</Item>

lib/tsc.js

+2-1
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: diag(2380, ts.DiagnosticCategory.Error, "get_and_set_accessor_must_have_the_same_type_2380", "'get' and 'set' accessor must have the same type."),
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}'."),
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,6 +3212,7 @@ 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}'."),
32153216
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}'."),
32163217
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}'."),
32173218
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

+9-2
Original file line numberDiff line numberDiff line change
@@ -21801,7 +21801,7 @@ namespace ts {
2180121801

2180221802
// TypeScript 1.0 spec (April 2014): 4.5
2180321803
// If both accessors include type annotations, the specified types must be identical.
21804-
checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, Diagnostics.get_and_set_accessor_must_have_the_same_type);
21804+
checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, Diagnostics.get_and_set_accessor_must_have_the_same_type_0_but_this_get_accessor_has_the_type_1);
2180521805
checkAccessorDeclarationTypesIdentical(node, otherAccessor, getThisTypeOfDeclaration, Diagnostics.get_and_set_accessor_must_have_the_same_this_type);
2180621806
}
2180721807
}
@@ -21817,7 +21817,14 @@ namespace ts {
2181721817
const firstType = getAnnotatedType(first);
2181821818
const secondType = getAnnotatedType(second);
2181921819
if (firstType && secondType && !isTypeIdenticalTo(firstType, secondType)) {
21820-
error(first, message);
21820+
21821+
if(isGetAccessor(first)){
21822+
const typeNameFirstType = typeToString(firstType);
21823+
const typeNameSecondType = typeToString(secondType);
21824+
21825+
const diagnostic: Diagnostic = error(first, message, typeNameSecondType, typeNameFirstType);
21826+
diagnostic.relatedInformation = [createDiagnosticForNode(first, Diagnostics.The_respective_set_accessor_has_the_type_0, typeNameSecondType)];
21827+
}
2182121828
}
2182221829
}
2182321830

src/compiler/diagnosticMessages.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@
13041304
"category": "Error",
13051305
"code": 2379
13061306
},
1307-
"'get' and 'set' accessor must have the same type.": {
1307+
"'get' and 'set' accessor must have the same type '{0}', but this 'get' accessor has the type '{1}'.": {
13081308
"category": "Error",
13091309
"code": 2380
13101310
},
@@ -2397,6 +2397,10 @@
23972397
"category": "Error",
23982398
"code": 2727
23992399
},
2400+
"The respective 'set' accessor has the type '{0}'.": {
2401+
"category": "Error",
2402+
"code": 2730
2403+
},
24002404

24012405
"Import declaration '{0}' is using private name '{1}'.": {
24022406
"category": "Error",

0 commit comments

Comments
 (0)