Title: Using 'Key in keyof ArrayType' always returns an Array regardles of the value manipulation applied · Issue #40069 · microsoft/TypeScript · GitHub
Open Graph Title: Using 'Key in keyof ArrayType' always returns an Array regardles of the value manipulation applied · Issue #40069 · microsoft/TypeScript
X Title: Using 'Key in keyof ArrayType' always returns an Array regardles of the value manipulation applied · Issue #40069 · microsoft/TypeScript
Description: TypeScript Version: 4.0.0-beta (same behaviour in version 3.5.1 v3.5.1-Play Ground) Search Terms: "key in keyof Array", "keyof Array" Expected behavior: using key in ArrayType has the same behaviour as on any object (returning an array t...
Open Graph Description: TypeScript Version: 4.0.0-beta (same behaviour in version 3.5.1 v3.5.1-Play Ground) Search Terms: "key in keyof Array", "keyof Array" Expected behavior: using key in ArrayType has the same behaviou...
X Description: TypeScript Version: 4.0.0-beta (same behaviour in version 3.5.1 v3.5.1-Play Ground) Search Terms: "key in keyof Array", "keyof Array" Expected behavior: using key in ArrayType h...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/40069
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using 'Key in keyof ArrayType' always returns an Array regardles of the value manipulation applied","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n--\u003e\r\n\r\n**TypeScript Version:** 4.0.0-beta (same behaviour in version 3.5.1 [v3.5.1-Play Ground](https://www.typescriptlang.org/play?strictPropertyInitialization=false\u0026useDefineForClassFields=true\u0026allowUnusedLabels=true\u0026noEmitHelpers=true\u0026noUnusedLocals=true\u0026noUnusedParameters=true\u0026esModuleInterop=false\u0026preserveConstEnums=true\u0026declaration=false\u0026target=99\u0026jsx=0\u0026ts=3.5.1#))\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) --\u003e\r\n**Search Terms:**\r\n\"key in keyof Array\", \"keyof Array\"\r\n\r\n**Expected behavior:**\r\nusing ```key in ArrayType``` has the same behaviour as on any object *(returning an array type only if the relevant properties are unchanged)*\r\n\r\n**Actual behavior:**\r\nusing ```key in ArrayType``` performs actions on touple entries but the returned type allways includes all default Array properties\r\n\r\n***Extention note:***\r\nNot the point of this issue and i know there are other issues around this topic. it's just a note,\r\nbut how about possibly adding tupple functionality for ArrayLike-, Map- and Set-types? They have all the basic qualities of a tupple, and it would be awesome to use them in a similar fashion (especially inference of ```Map.prototype.get/set``` and ```[Symbol.iterator]``` inference of tupples)\r\n\r\n\u003c!-- Did you find other bugs that looked similar? --\u003e\r\n**Related Issues:**\r\n#39726 \r\n#34780\r\n[type-fest/issues/119](https://github.com/sindresorhus/type-fest/issues/119) *(external library, but about this this behaviour and includes adHoc fix)*\r\n\r\n**Code**\r\n\r\n```ts\r\ntype Arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\r\ntype Arr2 = (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9)[]\r\ntype WhoopMyArray_Faulty\u003cBase extends ArrayLike\u003cany\u003e, Condition\u003e = { \r\n\t\t[Key in keyof Base]:\r\n\t\t\tBase[Key] extends Condition\r\n\t\t\t\t? 'Whoop it'\r\n\t\t\t\t: Base[Key] extends Base[number] ? Base[Key] : never\r\n\t}\r\n\r\n// action is performed on array elements but return type is still a proper array\r\ntype WhoopedArray = WhoopMyArray_Faulty\u003cArr, 7 | 5 | 2\u003e\r\ntype WhoopedArrayKeys = WhoopMyArray_Faulty\u003cArr, 7 | 5 | 2\u003e[keyof Arr]\r\n\r\n// related side note, but not the main pont\r\n// no action performed. in line with 1st example, expected: (0 | 1 | 'Whoop it' | 3 | 4 | 'Whoop it' | 6 | 'Whoop it' | 8 | 9)[]\r\ntype WhoopedArray2 = WhoopMyArray_Faulty\u003cArr2, 7 | 5 | 2\u003e\r\ntype WhoopedArray2Keys = WhoopMyArray_Faulty\u003cArr, 7 | 5 | 2\u003e[keyof Arr]\r\n```\r\ninfered types:\r\n\r\n```d.ts\r\ntype WhoopedArray = [0, 1, \"Whoop it\", 3, 4, \"Whoop it\", 6, \"Whoop it\", 8, 9]\r\n\r\ntype WhoopedArrayKeys = 0 | \"Whoop it\" | 1 | 3 | 4 | 6 | 8 | 9 | 10 | (() =\u003e string) | (() =\u003e string) \r\n | (() =\u003e 0 | \"Whoop it\" | 1 | 3 | 4 | 6 | 8 | 9 | undefined) | ((...items: (0 | \"Whoop it\" | 1 | 3 | 4 | 6 | 8 | 9)[]) =\u003e number)\r\n | { ...; } | ... 22 more ... | (() =\u003e IterableIterator\u003c...\u003e)\r\n\r\ntype WhoopedArray2 = (0 | 7 | 5 | 2 | 1 | 3 | 4 | 6 | 8 | 9)[]\r\n\r\ntype WhoopedArray2Keys = 0 | \"Whoop it\" | 1 | 3 | 4 | 6 | 8 | 9 | 10 | (() =\u003e string) | (() =\u003e string)\r\n | (() =\u003e 0 | \"Whoop it\" | 1 | 3 | 4 | 6 | 8 | 9 | undefined) | ((...items: (0 | \"Whoop it\" | 1 | 3 | 4 | 6 | 8 | 9)[]) =\u003e number)\r\n| { ...; } | ... 22 more ... | (() =\u003e IterableIterator\u003c...\u003e)\r\n```\r\n\r\n\r\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eOutput\u003c/b\u003e\u003c/summary\u003e\r\n\r\n```ts\r\n\"use strict\";\r\n\r\n```\r\n\r\n\r\n\u003c/details\u003e\r\n\r\n\r\n\u003cdetails\u003e\u003csummary\u003e\u003cb\u003eCompiler Options\u003c/b\u003e\u003c/summary\u003e\r\n\r\n```json\r\n{\r\n \"compilerOptions\": {\r\n \"noImplicitAny\": true,\r\n \"strictNullChecks\": true,\r\n \"strictFunctionTypes\": true,\r\n \"strictBindCallApply\": true,\r\n \"noImplicitThis\": true,\r\n \"noImplicitReturns\": true,\r\n \"useDefineForClassFields\": true,\r\n \"alwaysStrict\": true,\r\n \"allowUnusedLabels\": true,\r\n \"noEmitHelpers\": true,\r\n \"noUnusedLocals\": true,\r\n \"noUnusedParameters\": true,\r\n \"preserveConstEnums\": true,\r\n \"experimentalDecorators\": true,\r\n \"emitDecoratorMetadata\": true,\r\n \"moduleResolution\": 2,\r\n \"target\": \"Latest\",\r\n \"module\": \"ESNext\"\r\n }\r\n}\r\n```\r\n\r\n\r\n\u003c/details\u003e\r\n\r\n**Playground Link:** [Provided](https://www.typescriptlang.org/play?strictPropertyInitialization=false\u0026useDefineForClassFields=true\u0026allowUnusedLabels=true\u0026noEmitHelpers=true\u0026noUnusedLocals=true\u0026noUnusedParameters=true\u0026esModuleInterop=false\u0026preserveConstEnums=true\u0026declaration=false\u0026target=99\u0026jsx=0\u0026ts=4.0.0-beta#code/C4TwDgpgBAggTnKBeKcIEMAmB7AdgGxCgG0AGAGigEZKAmSgZkoBZKBWSgNkoHZKAOSgE4AugFgAUJNCQoAdQAW2bGACyIeHHQgA+gDF0AV3ygAPACF0AZ2gQAHsAi5MV2Am0AZAJYBrCKfRcEAA+SgBhPEwvYC88YOQoAG8oKEkASDTiAGkIIi9cKD8QbAAzKEsbEQAudIyKiGzckSh7R2dXCOdo2NxajIB+KAByRWUwKGihvrSq8usGnJBm1qcXOZtiXEMAWwAjCDhmwfWFpqhZ3AgANwP0gF9JSQB6J6h0AGMYvAnXSDgS7BwbYQTBQb7odxECD4CDA3DAVy7QzACa4d74QyYCCudD4fBQK64wzYsFlTTaAB0YDg2GAtPAEGkDPkShUIPJIEWrhQoxU6g5+iMJhApk0vCgAB8oGxJVBaMFiEVSm5DkA)\r\n ","author":{"url":"https://github.com/KilianKilmister","@type":"Person","name":"KilianKilmister"},"datePublished":"2020-08-15T16:11:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/40069/TypeScript/issues/40069"}
| 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:d80f4588-2341-faa1-eae4-3f1a14d15999 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C88A:6E104:131B78:1B5D05:6A61FB38 |
| html-safe-nonce | 5f9e659003c6ffc7ee6be0c8d39e57c0b3bbba678cf9ffc66f10b602e9b9ac1c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODhBOjZFMTA0OjEzMUI3ODoxQjVEMDU6NkE2MUZCMzgiLCJ2aXNpdG9yX2lkIjoiMTc3MzgyNzg5ODgyOTA0NDUzNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 34d75aa83d200f079c968dbdf1c0a564a6df682bf2eacdf48c69882ca1d720fb |
| hovercard-subject-tag | issue:679602007 |
| 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/40069/issue_layout |
| twitter:image | https://opengraph.githubassets.com/65762d4bb9ab2a3dd2832475d26a706da821e38fe4ab3203d3a271532bd41076/microsoft/TypeScript/issues/40069 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/65762d4bb9ab2a3dd2832475d26a706da821e38fe4ab3203d3a271532bd41076/microsoft/TypeScript/issues/40069 |
| og:image:alt | TypeScript Version: 4.0.0-beta (same behaviour in version 3.5.1 v3.5.1-Play Ground) Search Terms: "key in keyof Array", "keyof Array" Expected behavior: using key in ArrayType has the same behaviou... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KilianKilmister |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9e41a6fd863e96b9c7e9185dc317bf107dbbf8cb10efd6dea957211963f33775 |
| 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 | 2ed5e9c44acb35dcc1d752e449d2a6f7a6164b7b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width