Description
TypeScript Version: 3.7.0-dev.20190913
Search Terms:
- index signature parameter type
- index signature union
Code
interface A {
[id : string | number] : boolean;
};
Expected behavior:
Either the following error message is displayed, or the error message makes it clear that only one of string
xor number
is permissible as an index signature parameter type.
TypeScript/src/compiler/diagnosticMessages.json
Lines 962 to 965 in 038d951
Actual behavior:
error TS1023: An index signature parameter type must be 'string' or 'number'.
To me, the expression string | number
is equivalent to the phrase "'string' or 'number'", but the phrasing is not precise.
Either the wrong error is being thrown, or this TS1023 should be clarified to say "...must be one of 'string' or 'number'." or "...must be either 'string' or 'number'."
TypeScript/src/compiler/diagnosticMessages.json
Lines 74 to 77 in 038d951
Playground Link:
(error not shown in Playground)
Related Issues:
I will fix this in a PR if you tell me whether TS1023 is the right error with a fixed message, or if TS1337 should be thrown instead of TS1023.