Title: Regression in 2.8 vs 2.7 for function accepting a union of "Guid" and T, and having, but not always utilising, a keyof T in second param · Issue #23131 · microsoft/TypeScript · GitHub
Open Graph Title: Regression in 2.8 vs 2.7 for function accepting a union of "Guid" and T, and having, but not always utilising, a keyof T in second param · Issue #23131 · microsoft/TypeScript
X Title: Regression in 2.8 vs 2.7 for function accepting a union of "Guid" and T, and having, but not always utilising, a keyof T in second param · Issue #23131 · microsoft/TypeScript
Description: TypeScript Version: 2.8.1 (MS Build NuGet package) Using "latest" Visual Studio 2017 plugin - v15.6.20202.3 Was working fine all the way through to 2.7.x until trying to update to released 2.8.x this morning Search Terms: keyof union Cod...
Open Graph Description: TypeScript Version: 2.8.1 (MS Build NuGet package) Using "latest" Visual Studio 2017 plugin - v15.6.20202.3 Was working fine all the way through to 2.7.x until trying to update to released 2.8.x th...
X Description: TypeScript Version: 2.8.1 (MS Build NuGet package) Using "latest" Visual Studio 2017 plugin - v15.6.20202.3 Was working fine all the way through to 2.7.x until trying to update to release...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/23131
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Regression in 2.8 vs 2.7 for function accepting a union of \"Guid\" and T, and having, but not always utilising, a keyof T in second param","articleBody":"**TypeScript Version:** 2.8.1 (MS Build NuGet package)\r\nUsing \"latest\" Visual Studio 2017 plugin - v15.6.20202.3\r\n\r\nWas working fine all the way through to 2.7.x until trying to update to released 2.8.x this morning\r\n\r\n**Search Terms:** keyof union\r\n\r\n**Code**\r\n```\r\n//function to conveniently allow passing in a guid, or an object that contains a guid at a known property\r\ndeclare function extractGuid\u003cT>(guidOrObject: Guid | T, idProperty: keyof T): Guid;\r\n\r\n//GUIDs are really just strings, so treat them as such. Adding toLowerCase() is a good way of enforcing this\r\ninterface Guid {\r\n toLowerCase(): string;\r\n __GuidBrand?: any;\r\n}\r\n\r\ninterface Person {\r\n id: Guid,\r\n name: string,\r\n address: string\r\n}\r\n\r\nvar c1: Guid = '12341234-1234-1234-1234-123412341234';\r\nvar g1 = extractGuid(c1, 'id'); //'id' was previously ignored\r\nvar c2: Person = {\r\n id: '12341234-1234-1234-1234-123412341234',\r\n name: 'my name',\r\n address: '1 way street'\r\n};\r\nvar g2 = extractGuid(c2, 'id');\r\n```\r\n\r\n**Expected behavior:**\r\nI don't get a compilation error on the line var g1 = ....\r\nThe 'id' property is effectively ignored because the `T` isn't being used\r\n\r\n**Actual behavior:**\r\nI get an error (also shown in playground below)\r\n`Argument of type '\"id\"' is not assignable to parameter of type '\"toLowerCase\" | \"__GuidBrand?\"'`\r\n\r\n**Playground Link:** \r\nhttp://www.typescriptlang.org/play/index.html#src=%2F%2Ffunction%20to%20conveniently%20allow%20passing%20in%20a%20guid%2C%20or%20an%20object%20that%20contains%20a%20guid%20at%20a%20known%20property%0D%0Adeclare%20function%20extractGuid%3CT%3E(guidOrObject%3A%20Guid%20%7C%20T%2C%20idProperty%3A%20keyof%20T)%3A%20Guid%3B%0D%0A%0D%0A%2F%2FGUIDs%20are%20really%20just%20strings%2C%20so%20treat%20them%20as%20such.%20%20Adding%20toLowerCase()%20is%20a%20good%20way%20of%20enforcing%20this%0D%0Ainterface%20Guid%20%7B%0D%0A%20%20%20%20toLowerCase()%3A%20string%3B%0D%0A%20%20%20%20__GuidBrand%3F%3A%20any%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20Person%20%7B%0D%0A%20%20id%3A%20Guid%2C%0D%0A%20%20name%3A%20string%2C%0D%0A%20%20address%3A%20string%0D%0A%7D%0D%0A%0D%0Avar%20c1%3A%20Guid%20%3D%20'12341234-1234-1234-1234-123412341234'%3B%0D%0Avar%20g1%20%3D%20extractGuid(c1%2C%20'id')%3B%20%20%2F%2F'id'%20was%20previously%20ignored%0D%0Avar%20c2%3A%20Person%20%3D%20%7B%0D%0A%20%20id%3A%20'12341234-1234-1234-1234-123412341234'%2C%0D%0A%20%20name%3A%20'my%20name'%2C%0D%0A%20%20address%3A%20'1%20way%20street'%0D%0A%7D%3B%0D%0Avar%20g2%20%3D%20extractGuid(c2%2C%20'id')%3B%0D%0A%0D%0A\r\n\r\n\r\n**Related Issues:**\r\nMaybe this one\r\nhttps://github.com/Microsoft/TypeScript/pull/22300#issuecomment-370090990\r\nIt talks about keyof and intersection (not union) types and branding similar to what I'm doing with the branded Guid. Not entirely sure it's related but it at least fits the timeline of being in 2.8 and not in 2.7.","author":{"url":"https://github.com/IanYates","@type":"Person","name":"IanYates"},"datePublished":"2018-04-03T23:32:22Z","url":"https://github.com/microsoft/TypeScript/issues/23131"}
| 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:1a7f402b-40d5-0ecf-1d54-2124cf89bed5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CEE0:269AD9:2C8C843:3B81447:6B01CECB |
| html-safe-nonce | a14b411349b4999bb10dcf6065e8f6b448f753bf807487e7f4fef6d11e7dbf65 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRUUwOjI2OUFEOToyQzhDODQzOjNCODE0NDc6NkIwMUNFQ0IiLCJ2aXNpdG9yX2lkIjoiMjA2OTQxNzc0NDQwMjU5OTYyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fd290ce04ac3e2c52eb7e27384d09477f8e58c41f23b8e1e1557409216bbf9e7 |
| hovercard-subject-tag | issue:311033817 |
| 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/23131/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bd0997e6ad55efc0e77610c48ed4ebdba4d5926b9fe9eeb439f025b4a1e040fa/microsoft/TypeScript/issues/23131 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bd0997e6ad55efc0e77610c48ed4ebdba4d5926b9fe9eeb439f025b4a1e040fa/microsoft/TypeScript/issues/23131 |
| og:image:alt | TypeScript Version: 2.8.1 (MS Build NuGet package) Using "latest" Visual Studio 2017 plugin - v15.6.20202.3 Was working fine all the way through to 2.7.x until trying to update to released 2.8.x th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | IanYates |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width