Title: Poor tuple support · Issue #20899 · microsoft/TypeScript · GitHub
Open Graph Title: Poor tuple support · Issue #20899 · microsoft/TypeScript
X Title: Poor tuple support · Issue #20899 · microsoft/TypeScript
Description: TypeScript Version: 2.7.0-dev.20171226 Code function getPromise(): Promise<[string, number]> { return Promise.resolve(['', 0]); } The above is an example, but it's not the only example of where TypeScript has trouble with tuples. Others ...
Open Graph Description: TypeScript Version: 2.7.0-dev.20171226 Code function getPromise(): Promise<[string, number]> { return Promise.resolve(['', 0]); } The above is an example, but it's not the only example of where Typ...
X Description: TypeScript Version: 2.7.0-dev.20171226 Code function getPromise(): Promise<[string, number]> { return Promise.resolve(['', 0]); } The above is an example, but it's not the only ex...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/20899
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Poor tuple support","articleBody":"\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 2.7.0-dev.20171226\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction getPromise(): Promise\u003c[string, number]> {\r\n\treturn Promise.resolve(['', 0]);\r\n}\r\n```\r\n\r\nThe above is an example, but it's not the only example of where TypeScript has trouble with tuples.\r\n\r\nOthers include:\r\n\r\n```ts\r\nlet a: [string, number] = ['', 0];\r\nlet b: [string, number] = a.slice();\r\n```\r\n\r\nThe above one is harder, but it'd be great if `array.slice()` and `array.slice(0)` could be used to clone tuples.\r\n\r\nhttps://github.com/Zarel/Pokemon-Showdown/blob/2b5654e307d7d65ee16c8bf55961b352c97c96e9/users.js#L1438\r\n\r\nThe above linked example disappeared when I tried to construct a simple equivalent testcase:\r\n\r\n```ts\r\nlet a = null as [string, string, object][] | null;\r\n\r\nif (a) {\r\n\ta.push(['', '', {}]);\r\n} else {\r\n\ta = [['', '', {}]];\r\n}\r\n```\r\n\r\nBut if you care to clone that repo, checkout that commit, and delete the `// @ts-ignore`, you'll get a similar error message as the others, where the tuple degrades to an array.\r\n\r\n**Expected behavior:**\r\n\r\nNo errors\r\n\r\n**Actual behavior:**\r\n\r\n```\r\ntest1.ts(2,2): error TS2322: Type 'Promise\u003c(string | number)[]>' is not assignable to type 'Promise\u003c[string, number]>'.\r\n Type '(string | number)[]' is not assignable to type '[string, number]'.\r\n Property '0' is missing in type '(string | number)[]'.\r\n```\r\n\r\n```\r\ntest1.ts(2,5): error TS2322: Type '(string | number)[]' is not assignable to type '[string, number]'.\r\n Property '0' is missing in type '(string | number)[]'.\r\n```\r\n\r\n```\r\nusers.js(1438,4): error TS2322: Type '(string | Connection)[][]' is not assignable to type '[string, string, Connection][] | null'.\r\n Type '(string | Connection)[][]' is not assignable to type '[string, string, Connection][]'.\r\n Type '(string | Connection)[]' is not assignable to type '[string, string, Connection]'.\r\n Property '0' is missing in type '(string | Connection)[]'.\r\n```","author":{"url":"https://github.com/Zarel","@type":"Person","name":"Zarel"},"datePublished":"2017-12-26T20:53:30Z","url":"https://github.com/microsoft/TypeScript/issues/20899"}
| 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:1473d7e2-bc41-e14b-ec65-e0f8c69ccfd7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8F8:157C65:9EAD6D:D51697:6B00ECB7 |
| html-safe-nonce | 399e8720fe479ae94006123010d4cdda1ee7bd59970057b5d9bf977f7bd7885b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEY4OjE1N0M2NTo5RUFENkQ6RDUxNjk3OjZCMDBFQ0I3IiwidmlzaXRvcl9pZCI6IjI3NzAxODM2ODQ5OTk5MzMxMTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 711e616d2999299c3bad6f67eccd8e98e6fd27392a6e86b1ba9eed3e0454a663 |
| hovercard-subject-tag | issue:284608901 |
| 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/20899/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5ba0d9c563e1f8f1d51507740b7bfd2caabbc01aad1582b6b81c16d82f2456b8/microsoft/TypeScript/issues/20899 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5ba0d9c563e1f8f1d51507740b7bfd2caabbc01aad1582b6b81c16d82f2456b8/microsoft/TypeScript/issues/20899 |
| og:image:alt | TypeScript Version: 2.7.0-dev.20171226 Code function getPromise(): Promise<[string, number]> { return Promise.resolve(['', 0]); } The above is an example, but it's not the only example of where Typ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Zarel |
| 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