mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Improved error messages for Union index signature params
This commit is contained in:
1 parent
0c089d8d66
commit
a0d827cfdf
7 files changed
+144
-1
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user