Title: Contextual inference of functions in tuple types failures · Issue #47226 · microsoft/TypeScript · GitHub
Open Graph Title: Contextual inference of functions in tuple types failures · Issue #47226 · microsoft/TypeScript
X Title: Contextual inference of functions in tuple types failures · Issue #47226 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms contextual inference tuple inference 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about contextual inference ⏯ Playground Link Playground l...
Open Graph Description: Bug Report 🔎 Search Terms contextual inference tuple inference 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about contextual ...
X Description: Bug Report 🔎 Search Terms contextual inference tuple inference 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about context...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/47226
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Contextual inference of functions in tuple types failures","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\n### 🔎 Search Terms\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-->\r\ncontextual inference\r\ntuple inference\r\n\r\n### 🕗 Version & 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-->\r\nThis is the behavior in every version I tried, and I reviewed the FAQ for entries about contextual inference\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-->\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?jsx=0&ts=4.6.0-dev.20220116#code/MYGwhgzhAEDKAuZ4FMA8AVAfNA3gWAChpoB6E6AJWXgFcAnAOxjGgDMaHh4BLAewejwAFkkFgA1shjwANNDAAHBSG5To3eIN7yQIaArq8AbtwAmyU2yYzCxMvIaWFNCELXDk0OlJoh40oUMaAHMhQTd9QwArZC5eOlt9GgAjFWBoYOoABWjYnn4AMTA4ugBPVApoZAAPFEcYbzBTfhBS6A5xBl4AdwYAbQBdOSzMAApE4gA6abA6YIgALmg+ieJoacnWJiWcZe51AUlS3lZKAaXR+CX0AEpoAF5sCj7uAegAXxsiNeIDXhiShcNmAlhQ7o9oFlVgNEjcLldoLcHtgsrhVvZuMEunRuAxguoALbKZAE5AMRD5BgbVbeWiMdqOZCsXEWeTMBilADciXehF5BEI8FKCk8BV42nuuDY4qWDBoBOSyDoH25BGA-AgmjAYt4CCQnklDGQ3TgFLQOrGN1VhHVTE0KE1AHkjQ95Dq9ShJpl4Dl-nk+AwiiVSuNvqNdqxxR9wdhpbwvsRRjHoAAmBOkciAXg3AOI7B3VdG8XFaB1YSu8lng2kVyw6XV6cjlCqVMLDwLmEGT4a8Pj8S1m82jhCthEI9kzgGq9thgbggejIZ2ebgwPq1noMBvyxV0N64zXIJrQE5VaoirisvqNrcbpvbm0azS7bwQXwI1jT2feBcfV0O+ALruRrwSwAMzRtaBBjrmuL5oW8DFripZ0DAWzSFWnijJcSw6smq69Dcgx3naghSPA6DdBKbrih6yBetkuRcAGQaVmUoaJsmACM6ZJsiqbpqgACCx51KYDT7s0DDFrh-QDGMbbzEs-Gdo+PYIv2MDvDcQ7gWOk5vjOc5kdoS4Mp0a6DAce4HkeNSniglgXpuSrXluLa2pqUpPi+SyeX4hnfpKv6GQBMrQKBGmqkAA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\nclass State\u003cT> {\r\n // Returns a function that takes t, applies it to all provided fns,\r\n // and pushes the results through the projector\r\n public getProjectionFactory\u003cR extends readonly unknown[], P>(\r\n ...args: [\r\n ...fns: { [i in keyof R]: (t: T) => R[i] },\r\n projector: (...a: R) => P\r\n ]\r\n ): (t: T) => P {\r\n // ignoring implementation...\r\n return undefined as any;\r\n }\r\n}\r\n\r\ntype Foo = { foo: number };\r\nconst aFooState = new State\u003cFoo>();\r\n\r\nconst testOne = aFooState.getProjectionFactory(\r\n ({ foo }) => foo,\r\n () => 2,\r\n // 👇 incorrectly inferred to be [unknown, number]\r\n (...args) => ({ result: args })\r\n);\r\n\r\n// 🚫 failureOne is [unknown, number] instead of expected [number, number]\r\nconst { result: failureOne } = testOne({ foo: 3 });\r\n\r\n// 👇 incorrectly infers fns to be ((t: Foo) => unknown)[]\r\nconst testTwo = aFooState.getProjectionFactory(\r\n () => 1,\r\n () => 2,\r\n \u003cA extends readonly unknown[]>(...args: A) => ({ result: args })\r\n);\r\n\r\n// 🚫 failureTwo is unknown[] instead of expected [number, number]\r\nconst { result: resultTwo } = testTwo({ foo: 3 });\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nThe `projector` and `fns` in the tuple type examples are incorrectly inferred.\r\n\r\n### 🙂 Expected behavior\r\n\r\n`projector` should be inferred as `(...args: [number, number]) => { result: [number, number] }` in the first test example.\r\n\r\n`fns` should be inferred as `[(t: Foo) => number, (t: Foo) => number]` in the second test example.\r\n","author":{"url":"https://github.com/david-shortman","@type":"Person","name":"david-shortman"},"datePublished":"2021-12-22T21:28:54Z","url":"https://github.com/microsoft/TypeScript/issues/47226"}
| 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:073bc8af-3313-4655-5f51-6d62b7943286 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E2E2:EA06E:2B5BC02:3724819:6B0194D5 |
| html-safe-nonce | 4a5b5f13bc6ce03366c7706833b994d6b194badc23cca453e50212939ec5261d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkUyOkVBMDZFOjJCNUJDMDI6MzcyNDgxOTo2QjAxOTRENSIsInZpc2l0b3JfaWQiOiI2NjYxOTk0OTk4MDYzNTM1MzE3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | fb7cb3cd25b11629e5ba748375a143fb679f61ca518c1e162e9acf7598a23e64 |
| hovercard-subject-tag | issue:1087201765 |
| 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/47226/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7cd911c194da82f524b43431139306ee617affe2ad39bbb4a22a6a4305bb20fd/microsoft/TypeScript/issues/47226 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7cd911c194da82f524b43431139306ee617affe2ad39bbb4a22a6a4305bb20fd/microsoft/TypeScript/issues/47226 |
| og:image:alt | Bug Report 🔎 Search Terms contextual inference tuple inference 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about contextual ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | david-shortman |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width