-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Domain: Literal TypesUnit types including string literal types, numeric literal types, Boolean literals, null, undefinedUnit types including string literal types, numeric literal types, Boolean literals, null, undefinedFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
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?
timruffles, mizunashi-mana, sue71, ty1824, buola and 227 moreSenorsen, marcomorain, goodmind, HerringtonDarkholme, icholy and 5 moreSenorsen, marcomorain, goodmind, HerringtonDarkholme, icholy and 5 moreSenorsen, wclr, marcomorain, goodmind, msemikin and 14 more
Metadata
Metadata
Assignees
Labels
Domain: Literal TypesUnit types including string literal types, numeric literal types, Boolean literals, null, undefinedUnit types including string literal types, numeric literal types, Boolean literals, null, undefinedFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript