Title: argument types inference breaks for specific object literal method syntax · Issue #26629 · microsoft/TypeScript · GitHub
Open Graph Title: argument types inference breaks for specific object literal method syntax · Issue #26629 · microsoft/TypeScript
X Title: argument types inference breaks for specific object literal method syntax · Issue #26629 · microsoft/TypeScript
Description: TypeScript Version: 3.1.0-dev.20180823 Search Terms: object literal method argument Code function goofus
Open Graph Description: TypeScript Version: 3.1.0-dev.20180823 Search Terms: object literal method argument Code function goofus
X Description: TypeScript Version: 3.1.0-dev.20180823 Search Terms: object literal method argument Code function goofus <ARGS extends any[]> (f: (...args: ARGS) => any ) {} goofus((a: string) => ({ do...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26629
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"argument types inference breaks for specific object literal method syntax","articleBody":"**TypeScript Version:** 3.1.0-dev.20180823\r\n\r\n**Search Terms:** object literal method argument\r\n\r\n**Code**\r\n```ts\r\nfunction goofus \u003cARGS extends any[]> (f: (...args: ARGS) => any ) {}\r\n\r\ngoofus((a: string) => ({ dog() { return a; } }));\r\ngoofus((a: string) => ({ dog: function() { return a; } }));\r\n```\r\n\r\n**Expected behavior:**\r\ninfers `ARGS === [string]`\r\n\r\n**Actual behavior:**\r\n`[ts] Argument of type '(a: string) => { dog(): string; }' is not assignable to parameter of type '() => any'.`\r\n\r\nNote that everything works correctly if you do any of the below:\r\n1. infer a single argument: `function gallant \u003cARG extends any> (f: (arg: ARG) => any ) {}`\r\n2. use arrow syntax in the object literal: `goofus((a: string) => ({ dog: () => a }));`\r\n3. use method syntax to return the object literal: `goofus(function (a: string) { return { dog() { return a; } } });`\r\n\r\n**Playground Link:** [link](https://www.typescriptlang.org/play/#src=function%20gallant%20%3CARG%20extends%20any%3E%20(f%3A%20(arg%3A%20ARG)%20%3D%3E%20any%20)%20%7B%7D%0D%0A%0D%0Agallant((a%3A%20string)%20%3D%3E%20(%7B%20dog%3A%20()%20%3D%3E%20a%20%7D))%3B%0D%0A%2F%2F%20infers%20ARG%20%3D%3D%3D%20string%0D%0A%0D%0Agallant((a%3A%20string)%20%3D%3E%20(%7B%20dog()%20%7B%20return%20a%3B%20%7D%20%7D))%3B%0D%0A%2F%2F%20infers%20ARG%20%3D%3D%3D%20string%0D%0A%0D%0Afunction%20goofus%20%3CARGS%20extends%20any%5B%5D%3E%20(f%3A%20(...args%3A%20ARGS)%20%3D%3E%20any%20)%20%7B%7D%0D%0A%0D%0Agoofus((a%3A%20string)%20%3D%3E%20(%7B%20dog%3A%20()%20%3D%3E%20a%20%7D))%3B%0D%0A%2F%2F%20infers%20ARGS%20%3D%3D%3D%20%5Bstring%5D%0D%0A%0D%0Agoofus((a%3A%20string)%20%3D%3E%20(%7B%20dog()%20%7B%20return%20a%3B%20%7D%20%7D))%3B%0D%0A%2F%2F%20expected%3A%20infers%20ARGS%20%3D%3D%3D%20%5Bstring%5D%0D%0A%2F%2F%20actual%3A%20%20%20%5Bts%5D%20Argument%20of%20type%20'(a%3A%20string)%20%3D%3E%20%7B%20dog()%3A%20string%3B%20%7D'%20is%20not%20assignable%20to%20parameter%20of%20type%20'()%20%3D%3E%20any'.%0D%0A)\r\n\r\n**Related Issues:** couldn't find any","author":{"url":"https://github.com/billba","@type":"Person","name":"billba"},"datePublished":"2018-08-23T10:46:06Z","url":"https://github.com/microsoft/TypeScript/issues/26629"}
| 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:3e8ba39b-2d25-8d20-074c-28a91530ba9e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E378:29AEE8:2736510:343F1F5:6B01AB47 |
| html-safe-nonce | fa187102bf54c048f88766d9fb5d984d496eb8f31f5412264f3395e157cc3c50 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzc4OjI5QUVFODoyNzM2NTEwOjM0M0YxRjU6NkIwMUFCNDciLCJ2aXNpdG9yX2lkIjoiNDY4NjE3ODQ4NzA1NTI2NDU4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 458e5c349fbfb93cd7cde2061ae3a48c0df6ac44a5621ab6df026f5899be06c2 |
| hovercard-subject-tag | issue:353325614 |
| 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/26629/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b11ad1be49220bf5cf48cc8e68edbd847b27742fa37bad5ac79b93a4344f8df0/microsoft/TypeScript/issues/26629 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b11ad1be49220bf5cf48cc8e68edbd847b27742fa37bad5ac79b93a4344f8df0/microsoft/TypeScript/issues/26629 |
| og:image:alt | TypeScript Version: 3.1.0-dev.20180823 Search Terms: object literal method argument Code function goofus |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | billba |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width