Title: Recursive generics in function parameters are inferred as {}, and produce funky Intellisense · Issue #17522 · microsoft/TypeScript · GitHub
Open Graph Title: Recursive generics in function parameters are inferred as {}, and produce funky Intellisense · Issue #17522 · microsoft/TypeScript
X Title: Recursive generics in function parameters are inferred as {}, and produce funky Intellisense · Issue #17522 · microsoft/TypeScript
Description: TypeScript Version: 2.4.2 Code function build
Open Graph Description: TypeScript Version: 2.4.2 Code function build
X Description: TypeScript Version: 2.4.2 Code function build<O extends Options<O>>(options: O) {} interface Options<TSelf> { data?: {}; processSelf(self: TSelf); } build({ data: { hello: "w...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/17522
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Recursive generics in function parameters are inferred as {}, and produce funky Intellisense","articleBody":"\u003c!-- BUGS: Please use this template. -->\r\n\r\n**TypeScript Version:** 2.4.2\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction build\u003cO extends Options\u003cO>>(options: O) {}\r\n\r\ninterface Options\u003cTSelf> {\r\n data?: {};\r\n processSelf(self: TSelf);\r\n}\r\n\r\nbuild({\r\n data: { hello: \"world\" },\r\n processSelf(self) {\r\n self.data.hello;\r\n }\r\n});\r\n```\r\n\r\n**Expected behavior:**\r\nThe inferred type of `O` should be the type of the options object passed in.\r\n`self` should be of type `O`.\r\n`self.data.hello` should be accessible within the `processSelf` function.\r\n\r\nIf this is not supposed to work, I would expect `O extends Options\u003cO>` to be an error.\r\n\r\n**Actual behavior:**\r\nThe inferred type of `O` is `Options\u003c{}>`.\r\n`self` is of type `{}`.\r\n`self.data.hello` is therefore not accessible.\r\n\r\nAdditionally, the Intellisense VSCode is providing for this seems to be wrong, or at least confusing. If this is unrelated then I'm happy to make a separate issue for that and remove it from here.\r\n\r\nAs these screenshots show, `self` is inferred as `{}` but it allows access to `self.data`. `self.data` is given type `any` according to the tooltip, but the error at `.hello` is\r\n\r\n> Property 'hello' does not exist on type '{}'.\r\n\r\n\r\nWhen I explicitly specify `self: {}`, `self.data` becomes an error.\r\n\r\n\r\n\r\n\r\n**Real scenario:**\r\nIn my real scenario `Options` has many more optional properties, and I want `self` to have only the properties specified, not every optional property. There are also many optional functions with the signature of `processSelf(self: TSelf)` and they do need to be part of the same options object.","author":{"url":"https://github.com/SamPruden","@type":"Person","name":"SamPruden"},"datePublished":"2017-07-31T01:23:19Z","url":"https://github.com/microsoft/TypeScript/issues/17522"}
| 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:d52b6e43-f704-0344-e5b6-24f934c93fdb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B260:1DCB8C:C975BB:10BBD7D:6B00F545 |
| html-safe-nonce | eee97ec30966d969b5c12cd0a6e2ef49037bb38a2a275c692e3b6fee4d26e0be |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjYwOjFEQ0I4QzpDOTc1QkI6MTBCQkQ3RDo2QjAwRjU0NSIsInZpc2l0b3JfaWQiOiI3OTU1NTcwNDYyNTAxNjk2ODM3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6e826472daa5580af94ecba587cae26725620653c8521491d690c0a9701527d4 |
| hovercard-subject-tag | issue:246623319 |
| 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/17522/issue_layout |
| twitter:image | https://opengraph.githubassets.com/565301280e357dcf40dbe38a9d34c8f8751b415a2524f3cd472256fcd27495cc/microsoft/TypeScript/issues/17522 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/565301280e357dcf40dbe38a9d34c8f8751b415a2524f3cd472256fcd27495cc/microsoft/TypeScript/issues/17522 |
| og:image:alt | TypeScript Version: 2.4.2 Code function build |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SamPruden |
| 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