Title: Inference of [a,b] to union type array is missing index signature [0]:A and [1]:B · Issue #9216 · microsoft/TypeScript · GitHub
Open Graph Title: Inference of [a,b] to union type array is missing index signature [0]:A and [1]:B · Issue #9216 · microsoft/TypeScript
X Title: Inference of [a,b] to union type array is missing index signature [0]:A and [1]:B · Issue #9216 · microsoft/TypeScript
Description: When calling a method declared as all
Open Graph Description: When calling a method declared as all
X Description: When calling a method declared as all<T1, T2>(values: [T1, T2]); I cannot use a union type array. TypeScript Version: 1.8.10 Code OK: $q.all([a, b]).then(/*...*/); Error: var promises = [a, b...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/9216
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inference of [a,b] to union type array is missing index signature [0]:A and [1]:B","articleBody":"When calling a method declared as `all\u003cT1, T2>(values: [T1, T2]);` I cannot use a union type array.\n\n**TypeScript Version:** \n\n1.8.10\n\n**Code**\nOK:\n\n``` ts\n$q.all([a, b]).then(/*...*/);\n```\n\nError:\n\n``` ts\nvar promises = [a, b];\n$q.all(promises).then(/*...*/);\n\n> TS2329 Index signature is missing in type '(IPromise\u003cA> | IPromise\u003cB>)[]'\n```\n\n**Expected behavior:**\nIt would be nice if both versions work, without explicitly reference types A and B. I think the problem is, that `[a, b]` infers to `(A|B)[]` instead of `[A,B]`, which should prevent me from `[a,b].push(new C())` (Is this the intension?). The problem is, that `(A|B)[]` looses the indexers `[0]: A` and `[1]: B`. I think that's what the error message wants to say? \nWould it be possible to infer `[a, b]` to something like `(A|B)[A, B]` which is compatible to \n\n``` ts\ninterface IAB {\n [i:number]: A|B;\n [0]:A;\n [1]:B;\n}\n```\n\nBtw. the error message is rather confusing, since `(A|B)[]` actually has an index signature.\n","author":{"url":"https://github.com/hansmaad","@type":"Person","name":"hansmaad"},"datePublished":"2016-06-16T12:00:31Z","url":"https://github.com/microsoft/TypeScript/issues/9216"}
| 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:b8c22762-41f7-5395-c1cf-6ec5fc66bceb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE2E:2C4BED:88246E:AE8E99:6B00EA40 |
| html-safe-nonce | e58c72d64ca0ccfd88e0e9afc66d9ff4689b4931bff5f205ae31935745f42b9c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTJFOjJDNEJFRDo4ODI0NkU6QUU4RTk5OjZCMDBFQTQwIiwidmlzaXRvcl9pZCI6Ijc3NTk1Nzk3MzE3MTE4MTQyMDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0140ae1c56d83928ec045dc0d006efbc93b6f8026af6b628d992e874c6514aed |
| hovercard-subject-tag | issue:160644577 |
| 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/9216/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a8c2438c61c02bf78bf6d98a0c05a5f3d37b2aa2eecec363f29cc2f45164fdd9/microsoft/TypeScript/issues/9216 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a8c2438c61c02bf78bf6d98a0c05a5f3d37b2aa2eecec363f29cc2f45164fdd9/microsoft/TypeScript/issues/9216 |
| og:image:alt | When calling a method declared as all |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hansmaad |
| 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