Title: Homomorphic mapped generic array type sometimes no longer seen as an array · Issue #57744 · microsoft/TypeScript · GitHub
Open Graph Title: Homomorphic mapped generic array type sometimes no longer seen as an array · Issue #57744 · microsoft/TypeScript
X Title: Homomorphic mapped generic array type sometimes no longer seen as an array · Issue #57744 · microsoft/TypeScript
Description: 🔎 Search Terms conditional, mapped, array 🕗 Version & Regression Information This changed in PR #57122 (I think... definitely between 5.3 and 5.4) ⏯ Playground Link Playground link 💻 Code type MustBeArray Open Graph Description: 🔎 Search Terms conditional, mapped, array 🕗 Version & Regression Information This changed in PR #57122 (I think... definitely between 5.3 and 5.4) ⏯ Playground Link Playground link 💻 Code type Must...
X Description: 🔎 Search Terms conditional, mapped, array 🕗 Version & Regression Information This changed in PR #57122 (I think... definitely between 5.3 and 5.4) ⏯ Playground Link Playground link 💻 Code type ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/57744
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Homomorphic mapped generic array type sometimes no longer seen as an array","articleBody":"### 🔎 Search Terms\r\n\r\nconditional, mapped, array\r\n\r\n### 🕗 Version \u0026 Regression Information\r\n\r\n- This changed in PR #57122 (I think... definitely between 5.3 and 5.4)\r\n\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link](https://www.typescriptlang.org/play?ts=5.5.0-dev.20240312#code/C4TwDgpgBAsgrgZ2AIQgQQE4YIYgDwAqUEAHsBAHYAmCU2FIA2gLoB8UAvFAQFA+iQoACQC2IwsTKUadBi3ZcipctVoU4IgEYQMLKAH4eUY7EQp0WXHgDeURgEkoASwpQA1hBAB7AGbdmAFxQAIxQAL7sAUYmFBAAbjoA3HwC0AAanMJieIwAzAA0UAAshQCsbDwA9JUmAHr6QA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ntype MustBeArray\u003cT extends any[]\u003e = T\r\n\r\ntype Hmm\u003cT extends any[]\u003e = T extends number[] ?\r\n MustBeArray\u003c{ [I in keyof T]: 1 }\u003e : // \u003c-- error!\r\n // ~~~~~~~~~~~~~~~~~~~~~\r\n // Type '{ [I in keyof T]: 1; }' does not satisfy the constraint 'any[]'.\r\n // Types of property 'toString' are incompatible.\r\n // Type 'number' is not assignable to type '() =\u003e string'.(2344)\r\n never;\r\n\r\ntype X = Hmm\u003c[3, 4, 5]\u003e\r\n// ^? type X = [1, 1, 1]\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\n`{[I in keyof T]: 1}` is not seen as an array type inside of `Hmm\u003cT\u003e`, causing a compiler error. Something about the conditional type re-constraining `T` to another array type causes it to fail.\r\n\r\n### 🙂 Expected behavior\r\n\r\nThe code should compile without error.\r\n\r\n### Additional information about the issue\r\n\r\nComes from [this Stack Overflow question](https://stackoverflow.com/q/78148685/2887218).\r\n\r\nI'm a bit concerned that I can't seem to work around this without `//@ts-ignore`, since the normal approaches of `Extract\u003cT, any[]\u003e` don't help (they end up just doing the same conditional type thing again which break things) and `T \u0026 any[]` kind of works but you end up with intersections of arrays which nobody likes.","author":{"url":"https://github.com/jcalz","@type":"Person","name":"jcalz"},"datePublished":"2024-03-12T17:28:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/57744/TypeScript/issues/57744"}
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:32f02d99-6374-68d2-96ae-3e0e49b9c511 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id A57C:E3661:8C6D71:C83106:6A6310C2 html-safe-nonce f36f13557d0c57ee82c36afe38c431e4269f4ef273be8c739eb9a8bbdfca41cb visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTdDOkUzNjYxOjhDNkQ3MTpDODMxMDY6NkE2MzEwQzIiLCJ2aXNpdG9yX2lkIjoiMTU4MDE4ODc4Mjg5Mjg4MDA2NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 visitor-hmac ac1fb4baa46c05491d6bff5a53135a9e48ac413e5b49f682c78258138a6a8569 hovercard-subject-tag issue:2182274131 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/57744/issue_layout twitter:image https://opengraph.githubassets.com/97546eeab32e201e48e25a18e53e778d94d928e623aa513bbe239fb38ca52f75/microsoft/TypeScript/issues/57744 twitter:card summary_large_image og:image https://opengraph.githubassets.com/97546eeab32e201e48e25a18e53e778d94d928e623aa513bbe239fb38ca52f75/microsoft/TypeScript/issues/57744 og:image:alt 🔎 Search Terms conditional, mapped, array 🕗 Version & Regression Information This changed in PR #57122 (I think... definitely between 5.3 and 5.4) ⏯ Playground Link Playground link 💻 Code type Must... og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username jcalz hostname github.com expected-hostname github.com None 1a6c056e02f174fffc096c521ec0ff6fb83e40a2ec8cb8875466ec1524872dd6 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 6a93e25585f487ddff9e3996c06d5b869d6e1828 ui-target full theme-color #1e2327 color-scheme light dark
URLs of crawlers that visited me.