Title: Inconsistent type inferring behavior · Issue #53776 · microsoft/TypeScript · GitHub
Open Graph Title: Inconsistent type inferring behavior · Issue #53776 · microsoft/TypeScript
X Title: Inconsistent type inferring behavior · Issue #53776 · microsoft/TypeScript
Description: Bug Report Hi, we're having issues using inline call of the generic function decorator in a specific context. Unfortunately, I couldn't find anything related to this on stackoverflow, or here. Please check out the code below and feel fre...
Open Graph Description: Bug Report Hi, we're having issues using inline call of the generic function decorator in a specific context. Unfortunately, I couldn't find anything related to this on stackoverflow, or here. Plea...
X Description: Bug Report Hi, we're having issues using inline call of the generic function decorator in a specific context. Unfortunately, I couldn't find anything related to this on stackoverflow, or he...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/53776
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent type inferring behavior","articleBody":"# Bug Report\r\n\r\nHi, we're having issues using inline call of the generic function decorator in a specific context. Unfortunately, I couldn't find anything related to this on stackoverflow, or here. Please check out the code below and feel free to let me know if more information/context is needed. Thanks!\r\n\r\n### 🔎 Search Terms\r\n\r\n* `infer generic`\r\n* `infer generic function`\r\n\r\n\u003c!--\r\n What search terms did you use when trying to find an existing bug report?\r\n List them here so people in the future can find this one more easily.\r\n--\u003e\r\n\r\n### 🕗 Version \u0026 Regression Information\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n--\u003e\r\nThis is the behavior in every version I tried, and I reviewed the FAQ for entries about **inference** and **generics**\r\n\r\n\r\n### ⏯ Playground Link\r\n\r\n\u003c!--\r\n A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n The TypeScript Workbench can be used for more complex setups, try\r\n https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n--\u003e\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=5.0.4#code/GYVwdgxgLglg9mABAEwKbFQJwIoiwTwB4AVAEQEMpyA+ACgG8BfALkXoChFEBHPTfAGJhWtAJSIAvNUQAFTHAC2MAM6oSFKtQDcnRAgDKICBFTLlI5JXKsyV8VMQA3ODGQ7G4jly4B6H4gA6IPZGdnZUAA8ABzhMKERQSFgEFFQIWMo1YhlyTHIFZURIqFQwZELwAGswOAB3MABtAF0AGkRiACVTEAAbKDpdRIgRIICo3Pzzdpy8gvtpOUUVLK7lXv6W3VHx2ansiYL2URF52XklVRJV9ekvRExUKBBMJDFJW91ff1HP+8fnpBDWjbA7KUQ6LiMdxhKD4KKoRAAQUwACMYFA8vwNORJGxdFF5PC4vhWMoMTAwABzdw6cLRWLxIbJJCUx7ItEY3L4bG0AD6rlYYBAChRWGOZyWl3Z6Mx3KszQ+XAeTxeEouqACD2UcB6jlQtAa9AJcCJsNYAHIAIwAJgAzObGE1wSEwmgMDg+PgGLpeAQhKw0Ok8iVaKyoNLOVirG1LQAGUSbLgGIwmMy0SxUTy-PzebwAPQA-L8M+QAsBYgBRcgQAAWtHSYG1PQ1PTglOdkM2HlpDbJiDD2NxgYyIbDEdl2Jj8Z0bqwuAI3q4vv4-v7j0numTxlMynTdjxuZzucQheLVjLlerdd7OpbbY7iEYXedQA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well--\u003e\r\n```ts\r\nfunction deferQuery\u003cTData\u003e({}: {\r\n queryFn: () =\u003e Promise\u003cTData\u003e;\r\n onSuccess: (data: TData) =\u003e void;\r\n}) {\r\n // ...\r\n}\r\n\r\nexport function decorate\u003cTParams extends unknown[], TResult\u003e(\r\n func: (...params: TParams) =\u003e Promise\u003cTResult\u003e,\r\n ...params: TParams\r\n): () =\u003e Promise\u003cTResult\u003e {\r\n return () =\u003e {\r\n // ...\r\n return func(...params);\r\n };\r\n}\r\n\r\ntype ArbitraryData = {\r\n property: string;\r\n};\r\n\r\nexport function getArbitraryData(_id: number): Promise\u003cArbitraryData[]\u003e {\r\n return Promise.resolve([{property: '123'}]);\r\n}\r\n\r\ndeferQuery({\r\n queryFn: decorate(getArbitraryData, 10),\r\n onSuccess(data) {\r\n // ^? (parameter) data: unknown\r\n data.forEach(console.log);\r\n },\r\n});\r\n\r\nconst getData = decorate(getArbitraryData, 10);\r\ndeferQuery({\r\n queryFn: getData,\r\n onSuccess(data) {\r\n // ^? (parameter) data: ArbitraryData[]\r\n data.forEach(console.log);\r\n },\r\n});\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\n`data` is typed as `ArbitraryData[]` only when the decorated method is stored in a variable.\r\n\r\n### 🙂 Expected behavior\r\n\r\n`data` is typed as `ArbitraryData[]` in both cases.\r\n\r\n```ts\r\ndeferQuery({\r\n queryFn: decorate(getArbitraryData, 10),\r\n onSuccess(data) {\r\n // ^? (parameter) data: ArbitraryData[]\r\n data.forEach(console.log);\r\n },\r\n});\r\n\r\nconst getData = decorate(getArbitraryData, 10);\r\ndeferQuery({\r\n queryFn: getData,\r\n onSuccess(data) {\r\n // ^? (parameter) data: ArbitraryData[]\r\n data.forEach(console.log);\r\n },\r\n});\r\n```\r\n","author":{"url":"https://github.com/chernodub","@type":"Person","name":"chernodub"},"datePublished":"2023-04-14T09:29:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/53776/TypeScript/issues/53776"}
| 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:a9d1a097-1f94-6111-9b6c-a96dfa9c3d2e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8318:841F:7681B:A02DD:6A6266BD |
| html-safe-nonce | 4c61b55e607595a62555172be248ca849cacb5af34ca0163ab328fd1e029506d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzE4Ojg0MUY6NzY4MUI6QTAyREQ6NkE2MjY2QkQiLCJ2aXNpdG9yX2lkIjoiNTg2NzQ2MTI0MTI1NTEyNjcxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fc8cac7ee1228ac00feb57dd6a5f8a50c90aeba4e4c674ef9bd48f90b122d734 |
| hovercard-subject-tag | issue:1667890887 |
| 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/53776/issue_layout |
| twitter:image | https://opengraph.githubassets.com/337c6ab8fab43a75c241f480c3f807f0c18f5699745ec0076a58fbfc8f80aa12/microsoft/TypeScript/issues/53776 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/337c6ab8fab43a75c241f480c3f807f0c18f5699745ec0076a58fbfc8f80aa12/microsoft/TypeScript/issues/53776 |
| og:image:alt | Bug Report Hi, we're having issues using inline call of the generic function decorator in a specific context. Unfortunately, I couldn't find anything related to this on stackoverflow, or here. Plea... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | chernodub |
| hostname | github.com |
| expected-hostname | github.com |
| None | 194bddaed53c0eb07047629c520853f4208e77a17ff57428346485cc202e39f2 |
| 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 | c2862cf2db52f0c7f6cba3de21ffeeafe7c5456e |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width