Closed
Description
According to #5185, string literal types are assignable to plain strings. Given the following type definition:
type NodeType = "IfStatement"
| "WhileStatement"
| "ForStatement";
Both these assignments are valid:
const nodeType1: NodeType = "IfStatement";
const nodeType2: string = nodeType1;
However, string literal types currently can't be used as index signature parameter types. Therefore, the compiler complains about the following code:
let keywords: { [index: NodeType]: string } = {
"IfStatement": "if",
"WhileStatement": "while",
"ForStatement": "for"
};
// error TS1023: An index signature parameter type must be 'string' or 'number'.
Shouldn't that scenario be supported, given that string literal types are assignable to strings?