Title: Argument inference change in 3.4.4 · Issue #31297 · microsoft/TypeScript · GitHub
Open Graph Title: Argument inference change in 3.4.4 · Issue #31297 · microsoft/TypeScript
X Title: Argument inference change in 3.4.4 · Issue #31297 · microsoft/TypeScript
Description: TypeScript Version: 3.4.4-dev.20190507 Search Terms: 3.4.4 generic argument inference Code function wrap
Open Graph Description: TypeScript Version: 3.4.4-dev.20190507 Search Terms: 3.4.4 generic argument inference Code function wrap
X Description: TypeScript Version: 3.4.4-dev.20190507 Search Terms: 3.4.4 generic argument inference Code function wrap<Self>( creator: (self: Self) => Self ) {} wrap(self => ({ val: 2, func(): number...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/31297
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Argument inference change in 3.4.4","articleBody":"**TypeScript Version:** 3.4.4-dev.20190507\r\n\r\n**Search Terms:** 3.4.4 generic argument inference\r\n\r\n**Code**\r\n```ts\r\nfunction wrap\u003cSelf>(\r\n creator: (self: Self) => Self\r\n) {}\r\n\r\nwrap(self => ({\r\n val: 2,\r\n\r\n func(): number {\r\n return self.val;\r\n },\r\n}));\r\n```\r\n\r\n**Expected behavior:**\r\nExpected to compile without any errors, with the type of `self` inferred as `{ val: number, func(): number }`. This works as expected from v3.1 -> 3.4.3\r\n\r\n**Actual behavior:**\r\nAs of 3.4.4 this no longer works. Looks like `self` is being inferred as `{}`. TypeScript emits the following error at `return self.val`: \r\n\r\n> 9:17 - error TS2339: Property 'val' does not exist on type '{}'.\r\n\r\nI tested this with TypeScript@3.5.0-dev.20190507 and it looks like `self` is being inferred as `unknown`. It emits the following error: \r\n\r\n> 9:12 - error TS2571: Object is of type 'unknown'.\r\n\r\n**Playground Link:** \r\n[works in older version of TypeScript](https://www.typescriptlang.org/play/index.html#src=function%20wrap%3CSelf%3E(%0D%0A%20%20creator%3A%20(self%3A%20Self)%20%3D%3E%20Self%0D%0A)%20%7B%7D%0D%0A%0D%0Awrap(self%20%3D%3E%20(%7B%0D%0A%20%20val%3A%202%2C%0D%0A%0D%0A%20%20func()%3A%20number%20%7B%0D%0A%20%20%20%20return%20self.val%3B%0D%0A%20%20%7D%2C%0D%0A%7D))%3B%0D%0A)\r\n","author":{"url":"https://github.com/zcregan","@type":"Person","name":"zcregan"},"datePublished":"2019-05-07T18:24:43Z","url":"https://github.com/microsoft/TypeScript/issues/31297"}
| 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:f1a0aa70-7f33-3c3c-7851-2fabab15f4bc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DB48:EDA7A:CEA350:1077930:6B0101C3 |
| html-safe-nonce | 3ea909f9b55e27b0a938742daa95b03b5fa600edc5148f360b13e562c2729824 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjQ4OkVEQTdBOkNFQTM1MDoxMDc3OTMwOjZCMDEwMUMzIiwidmlzaXRvcl9pZCI6IjY4Njk2MDAwNTkxNTYxMzYzODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | bff72e09106b2714ac3f93d1a65e679efc8026e05c74f68aedb1521b0de0c594 |
| hovercard-subject-tag | issue:441383487 |
| 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/31297/issue_layout |
| twitter:image | https://opengraph.githubassets.com/95bb73967c9d93113de838433a878cc47f7b04cab9b5e7076d05f96d5c103e3f/microsoft/TypeScript/issues/31297 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/95bb73967c9d93113de838433a878cc47f7b04cab9b5e7076d05f96d5c103e3f/microsoft/TypeScript/issues/31297 |
| og:image:alt | TypeScript Version: 3.4.4-dev.20190507 Search Terms: 3.4.4 generic argument inference Code function wrap |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zcregan |
| 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