Title: Breaking change in string enum member type in v3.6 · Issue #33403 · microsoft/TypeScript · GitHub
Open Graph Title: Breaking change in string enum member type in v3.6 · Issue #33403 · microsoft/TypeScript
X Title: Breaking change in string enum member type in v3.6 · Issue #33403 · microsoft/TypeScript
Description: In order to check whether a given string is a member of a string Enum, I use the code shown below. There seems to be an unintentional breaking change in v3.6.2 and later - this code compiles just fine in v3.3.x - v3.5.x. Search Terms: en...
Open Graph Description: In order to check whether a given string is a member of a string Enum, I use the code shown below. There seems to be an unintentional breaking change in v3.6.2 and later - this code compiles just f...
X Description: In order to check whether a given string is a member of a string Enum, I use the code shown below. There seems to be an unintentional breaking change in v3.6.2 and later - this code compiles just f...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/33403
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Breaking change in string enum member type in v3.6","articleBody":"In order to check whether a given string is a member of a string Enum, I use the code shown below. There seems to be an unintentional breaking change in v3.6.2 and later - this code compiles just fine in v3.3.x - v3.5.x.\r\n\r\n**Search Terms:** enum, includes, string enum\r\n\r\n**Code**\r\n\r\n```ts\r\nenum Colors {\r\n Red = 'red',\r\n Green = 'green',\r\n Blue = 'blue',\r\n}\r\n\r\nconst a: string = 'orange';\r\nconst b = Object.values(Colors); // in \u003c3.6: any[], in >=3.6 Color[]\r\nconst c = Object.values(Colors).includes(a)\r\n```\r\n\r\n**Expected behavior:** Compiles successfully 👍 \r\n\r\n**Actual behavior:** Error on L9 (on call site for `includes(...)`)\r\n\r\n```\r\nArgument of type 'string' is not assignable to parameter of type 'Colors'.ts(2345)\r\n```\r\n\r\nThe `Object.values` type definition doesn't change across these versions, and is the following:\r\n\r\n```ts\r\ninterface ObjectConstructor {\r\n /**\r\n * Returns an array of values of the enumerable properties of an object\r\n * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.\r\n */\r\n values\u003cT>(o: { [s: string]: T } | ArrayLike\u003cT>): T[];\r\n\r\n /**\r\n * Returns an array of values of the enumerable properties of an object\r\n * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.\r\n */\r\n values(o: {}): any[];\r\n}\r\n```\r\n\r\nSo it seems that string Enums have begun to match the interface `{ [s: string]: T }` where they didn't before. I can understand why it might, but is this intended?","author":{"url":"https://github.com/aoberoi","@type":"Person","name":"aoberoi"},"datePublished":"2019-09-12T23:42:08Z","url":"https://github.com/microsoft/TypeScript/issues/33403"}
| 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:0ff5a381-73a7-c5da-2cd4-457221d3a366 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B8C2:31E99C:9EFF1A:D615F9:6B00EBC1 |
| html-safe-nonce | b047f0c76e2c727a02bb0fc91a9ee34608279881d4ccb0027394f46156e2bd65 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOEMyOjMxRTk5Qzo5RUZGMUE6RDYxNUY5OjZCMDBFQkMxIiwidmlzaXRvcl9pZCI6IjQzNjU0NTg4MzkzODI4NDY0MDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 786844f4ae2f69ab9e294a6513eb9f15d447a67ab205d9c94db461b4b857aedb |
| hovercard-subject-tag | issue:493076544 |
| 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/33403/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bc809d9dc77467528103f002a331557137a2be87011beb3260a3d89379705874/microsoft/TypeScript/issues/33403 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bc809d9dc77467528103f002a331557137a2be87011beb3260a3d89379705874/microsoft/TypeScript/issues/33403 |
| og:image:alt | In order to check whether a given string is a member of a string Enum, I use the code shown below. There seems to be an unintentional breaking change in v3.6.2 and later - this code compiles just f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aoberoi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width