Title: Function can return wrong values despite type · Issue #30603 · microsoft/TypeScript · GitHub
Open Graph Title: Function can return wrong values despite type · Issue #30603 · microsoft/TypeScript
X Title: Function can return wrong values despite type · Issue #30603 · microsoft/TypeScript
Description: TypeScript Version: 3.4.0-dev.20190326 Search Terms: Function Generic Extends Keyof Property Code interface Type { a: 123; b: "some string"; } function get123
Open Graph Description: TypeScript Version: 3.4.0-dev.20190326 Search Terms: Function Generic Extends Keyof Property Code interface Type { a: 123; b: "some string"; } function get123
X Description: TypeScript Version: 3.4.0-dev.20190326 Search Terms: Function Generic Extends Keyof Property Code interface Type { a: 123; b: "some string"; } function get123<K extends keyof Type>(...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/30603
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Function can return wrong values despite type","articleBody":"\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.4.0-dev.20190326\r\n\r\n**Search Terms:** Function Generic Extends Keyof Property\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface Type {\r\n a: 123;\r\n b: \"some string\";\r\n}\r\n\r\nfunction get123\u003cK extends keyof Type>(): Type[K] {\r\n return 123;\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nThe function `get123` would yield an error as the return type might not be correct as it depends on `K`.\r\n\r\n**Actual behavior:**\r\nNo error for `get123`. That function would obviously always return 123. \r\n\r\n\r\n**Playground Link:** [Example on TypeScript Playground](https://www.typescriptlang.org/play/#src=interface%20Type%20%7B%0D%0A%20%20a%3A%20123%3B%0D%0A%20%20b%3A%20%22some%20string%22%3B%0D%0A%7D%0D%0A%0D%0Afunction%20get123%3CK%20extends%20keyof%20Type%3E()%3A%20Type%5BK%5D%20%7B%0D%0A%20%20return%20123%3B%0D%0A%7D%0D%0A)\r\n\u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\n","author":{"url":"https://github.com/bjornua","@type":"Person","name":"bjornua"},"datePublished":"2019-03-26T20:45:34Z","url":"https://github.com/microsoft/TypeScript/issues/30603"}
| 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:36ae54ce-31f4-799b-1eaf-6ff26edf497a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 900C:2E5652:820CF6:A6F3A2:6B00E8CD |
| html-safe-nonce | 0100432d3308a2f5cb965aee126316b91d32337e88c548130a85251c1f08e046 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDBDOjJFNTY1Mjo4MjBDRjY6QTZGM0EyOjZCMDBFOENEIiwidmlzaXRvcl9pZCI6IjIwODkxNTUzOTk3NTUyOTQ5MjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3c5726627cd12e4e4e77a5ac6fe0e541ceff2fb15b8653da81820909084eb8eb |
| hovercard-subject-tag | issue:425640539 |
| 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/30603/issue_layout |
| twitter:image | https://opengraph.githubassets.com/50061a561d64a05caad724049077e7ab1d1183e6a2dddd985c5952e3b03275aa/microsoft/TypeScript/issues/30603 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/50061a561d64a05caad724049077e7ab1d1183e6a2dddd985c5952e3b03275aa/microsoft/TypeScript/issues/30603 |
| og:image:alt | TypeScript Version: 3.4.0-dev.20190326 Search Terms: Function Generic Extends Keyof Property Code interface Type { a: 123; b: "some string"; } function get123 |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bjornua |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width