Improved error messages for Union index signature params

This commit is contained in:
kujon committed 2017-12-15 21:44:37 +00:00
1 parent 0c089d8d66
commit a0d827cfdf
7 files changed
+144 -1

No files matched your search

+4
View File
@@ -25781,6 +25781,10 @@ namespace ts {
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_cannot_be_a_type_alias_Use_index_Colon_0_instead, typeToString(type));
}
if (type.flags & TypeFlags.Union && forEach((<UnionType>type).types, t => !!(t.flags & TypeFlags.StringOrNumberLiteral))) {
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_cannot_be_a_union_type_Use_K_in_0_instead, symbolName(type.aliasSymbol));
}
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_must_be_string_or_number);
}
if (!node.type) {
+4
View File
@@ -943,6 +943,10 @@
"category": "Error",
"code": 1336
},
"An index signature parameter type cannot be a union type. Use '[K in {0}]' instead.": {
"category": "Error",
"code": 1337
},
"Duplicate identifier '{0}'.": {
"category": "Error",