Title: Cloning a tuple turns it into an array · Issue #16503 · microsoft/TypeScript · GitHub
Open Graph Title: Cloning a tuple turns it into an array · Issue #16503 · microsoft/TypeScript
X Title: Cloning a tuple turns it into an array · Issue #16503 · microsoft/TypeScript
Description: TypeScript Version: every version tested (from 2.3.0 to 2.5.0-dev.20170613) Code type Tuple = [number, number]; let t1: Tuple = [1, 2]; let t2: Tuple = t1.slice(); let t3: Tuple = t1.slice(0); let t4: Tuple = [...t1]; Expected behavior: ...
Open Graph Description: TypeScript Version: every version tested (from 2.3.0 to 2.5.0-dev.20170613) Code type Tuple = [number, number]; let t1: Tuple = [1, 2]; let t2: Tuple = t1.slice(); let t3: Tuple = t1.slice(0); let ...
X Description: TypeScript Version: every version tested (from 2.3.0 to 2.5.0-dev.20170613) Code type Tuple = [number, number]; let t1: Tuple = [1, 2]; let t2: Tuple = t1.slice(); let t3: Tuple = t1.slice(0); let ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/16503
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cloning a tuple turns it into an array","articleBody":"**TypeScript Version:** every version tested (from 2.3.0 to 2.5.0-dev.20170613)\r\n\r\n**Code**\r\n\r\n```ts\r\ntype Tuple = [number, number];\r\nlet t1: Tuple = [1, 2];\r\nlet t2: Tuple = t1.slice();\r\nlet t3: Tuple = t1.slice(0);\r\nlet t4: Tuple = [...t1];\r\n```\r\n\r\n**Expected behavior:**\r\nNo error\r\n\r\n**Actual behavior:**\r\n```\r\ntest-slice.ts(3,5): error TS2322: Type 'number[]' is not assignable to type '[number, number]'.\r\n Property '0' is missing in type 'number[]'.\r\ntest-slice.ts(4,5): error TS2322: Type 'number[]' is not assignable to type '[number, number]'.\r\ntest-slice.ts(5,5): error TS2322: Type 'number[]' is not assignable to type '[number, number]'.\r\n```\r\n\r\n`array.slice()` and `array.slice(0)` and `[...array]` are common idiomatic ways to shallow-clone an array. Unfortunately, this loses the tuple type information.\r\n\r\nI don't know how easy this would be to fix, but even something like supporting only tuples below a certain length (by hardcoding `[T1, T2] => [T1, T2]` type signatures for `Array#slice`) would be a pretty big improvement for my own use-case.","author":{"url":"https://github.com/Zarel","@type":"Person","name":"Zarel"},"datePublished":"2017-06-13T20:25:19Z","url":"https://github.com/microsoft/TypeScript/issues/16503"}
| 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:726b0fdb-7b5f-8d34-aaa0-6d2a39962921 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 905E:1F7384:AE4A93:E7ECD6:6B00ED2E |
| html-safe-nonce | b720d398f1e2ff76f3b260d2b6f6d6df2e2f8b669fa0895b3944509667236fd7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDVFOjFGNzM4NDpBRTRBOTM6RTdFQ0Q2OjZCMDBFRDJFIiwidmlzaXRvcl9pZCI6IjYyMTUzMjcyNjgzODY5NTg2MzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1146dfdb9fdbc007d84d9a84cab664e4f1aee9d8b3f95ce0f45253a25b170017 |
| hovercard-subject-tag | issue:235681768 |
| 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/16503/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f94da247456ca56fd01459bf9cbbab692a94ae8615e837145c583a16f9bf874f/microsoft/TypeScript/issues/16503 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f94da247456ca56fd01459bf9cbbab692a94ae8615e837145c583a16f9bf874f/microsoft/TypeScript/issues/16503 |
| og:image:alt | TypeScript Version: every version tested (from 2.3.0 to 2.5.0-dev.20170613) Code type Tuple = [number, number]; let t1: Tuple = [1, 2]; let t2: Tuple = t1.slice(); let t3: Tuple = t1.slice(0); let ... |
| 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