Title: Property '[mySymbol]' is not assignable to string index type · Issue #20146 · microsoft/TypeScript · GitHub
Open Graph Title: Property '[mySymbol]' is not assignable to string index type · Issue #20146 · microsoft/TypeScript
X Title: Property '[mySymbol]' is not assignable to string index type · Issue #20146 · microsoft/TypeScript
Description: TypeScript Version: 2.7.0-dev.20171118 Code I was expecting this to work after #15473 was merged: const mySymbol = Symbol('My Symbol'); interface TypeA { [mySymbol]: Function; // OK [x: number]: number; } interface TypeB { [mySymbol]: Fu...
Open Graph Description: TypeScript Version: 2.7.0-dev.20171118 Code I was expecting this to work after #15473 was merged: const mySymbol = Symbol('My Symbol'); interface TypeA { [mySymbol]: Function; // OK [x: number]: nu...
X Description: TypeScript Version: 2.7.0-dev.20171118 Code I was expecting this to work after #15473 was merged: const mySymbol = Symbol('My Symbol'); interface TypeA { [mySymbol]: Function; // OK [x: num...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/20146
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Property '[mySymbol]' is not assignable to string index type","articleBody":"\r\n**TypeScript Version:** 2.7.0-dev.20171118\r\n\r\n**Code**\r\n\r\nI was expecting this to work after #15473 was merged:\r\n\r\n```ts\r\nconst mySymbol = Symbol('My Symbol');\r\n\r\ninterface TypeA {\r\n [mySymbol]: Function; // OK\r\n [x: number]: number;\r\n}\r\n\r\ninterface TypeB {\r\n [mySymbol]: Function; // ERROR: Property '[mySymbol]' is not assignable to string index type\r\n [x: string]: string;\r\n}\r\n\r\nlet a: TypeA, b: TypeB;\r\nlet a1 = a[mySymbol]; // a1 has type Function\r\nlet a2 = a[42]; // a2 has type number\r\nlet b1 = b[mySymbol]; // b1 has type Function\r\nlet b2 = b['foo']; // b2 has type string\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nNo compiler errors. `mySymbol` is a unique symbol as per #15473 and should not overlap either numeric index types or string index types.\r\n\r\n**Actual behavior:**\r\n\r\nError in `TypeB` as shown in the code above. TSC rejects the unique symbol key because it is not compatible with the string index type, even though it is not a string property key.\r\n\r\nNote that the types of `a1`, `a2`, `b1` and `b2` are all inferred correctly despite the compile error.\r\n","author":{"url":"https://github.com/yortus","@type":"Person","name":"yortus"},"datePublished":"2017-11-20T06:14:04Z","url":"https://github.com/microsoft/TypeScript/issues/20146"}
| 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:59fb8ae2-8c81-842a-0229-ba608967b331 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 85B6:361639:DA022C:1238710:6B0104D2 |
| html-safe-nonce | 4e693197e313a624e6508d3e7316862ee920afea07665c10f35e8c7c976f9024 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUI2OjM2MTYzOTpEQTAyMkM6MTIzODcxMDo2QjAxMDREMiIsInZpc2l0b3JfaWQiOiIxMzQ4MjQwMTA5MTY5ODcwMDM0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 52a88b40ec4013893220464c4fabf164c8167fdc805be3e4cf47b606ea361bb6 |
| hovercard-subject-tag | issue:275247427 |
| 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/20146/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0ab762614d1d1c7925913822b5e65cabde238951ad1fd7ce1d1570a1853d7bfa/microsoft/TypeScript/issues/20146 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0ab762614d1d1c7925913822b5e65cabde238951ad1fd7ce1d1570a1853d7bfa/microsoft/TypeScript/issues/20146 |
| og:image:alt | TypeScript Version: 2.7.0-dev.20171118 Code I was expecting this to work after #15473 was merged: const mySymbol = Symbol('My Symbol'); interface TypeA { [mySymbol]: Function; // OK [x: number]: nu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yortus |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width