Title: String literal types as index signature parameter types? · Issue #5683 · microsoft/TypeScript · GitHub
Open Graph Title: String literal types as index signature parameter types? · Issue #5683 · microsoft/TypeScript
X Title: String literal types as index signature parameter types? · Issue #5683 · microsoft/TypeScript
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...
Open Graph Description: According to #5185, string literal types are assignable to plain strings. Given the following type definition: type NodeType = "IfStatement" | "WhileStatement" | "ForStatement"; Both these assignme...
X Description: According to #5185, string literal types are assignable to plain strings. Given the following type definition: type NodeType = "IfStatement" | "WhileStatement" | "ForStatem...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/5683
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"String literal types as index signature parameter types?","articleBody":"According to https://github.com/Microsoft/TypeScript/pull/5185, string literal types are assignable to plain strings. Given the following type definition:\n\n``` ts\ntype NodeType = \"IfStatement\"\n | \"WhileStatement\"\n | \"ForStatement\";\n```\n\nBoth these assignments are valid:\n\n``` ts\nconst nodeType1: NodeType = \"IfStatement\";\nconst nodeType2: string = nodeType1;\n```\n\nHowever, string literal types currently can't be used as index signature parameter types. Therefore, the compiler complains about the following code:\n\n``` ts\nlet keywords: { [index: NodeType]: string } = {\n \"IfStatement\": \"if\",\n \"WhileStatement\": \"while\",\n \"ForStatement\": \"for\"\n};\n\n// error TS1023: An index signature parameter type must be 'string' or 'number'.\n```\n\nShouldn't that scenario be supported, given that string literal types are assignable to strings?\n\n/cc @DanielRosenwasser\n","author":{"url":"https://github.com/mariusschulz","@type":"Person","name":"mariusschulz"},"datePublished":"2015-11-16T14:38:46Z","url":"https://github.com/microsoft/TypeScript/issues/5683"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b6aca229-3a82-3c17-f048-0ce35bf8f4bd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E410:1F855F:FF401E:160E483:6AFBFB18 |
| html-safe-nonce | f552531accc63a7b0ec89be34f62b2b0c68dd9f4da0f5fb9747cfb8ebeaebd07 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDEwOjFGODU1RjpGRjQwMUU6MTYwRTQ4Mzo2QUZCRkIxOCIsInZpc2l0b3JfaWQiOiI2ODI0NTMzOTMzNjg2NTIwNjAwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f0d357f57855612cab3ba1a4176c34a8b9b0468ab936876338df65212123ea53 |
| hovercard-subject-tag | issue:117138062 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/5683/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dd34454416360b19232fb814f72e1770d4279f951ec7b8fa1fbb23c1061e284b/microsoft/TypeScript/issues/5683 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dd34454416360b19232fb814f72e1770d4279f951ec7b8fa1fbb23c1061e284b/microsoft/TypeScript/issues/5683 |
| og:image:alt | According to #5185, string literal types are assignable to plain strings. Given the following type definition: type NodeType = "IfStatement" | "WhileStatement" | "ForStatement"; Both these assignme... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mariusschulz |
| hostname | github.com |
| expected-hostname | github.com |
| None | fa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b3b5633a74535d9c23385512d534c66c8fde1907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width