Title: Conditional type does not narrow union type · Issue #29188 · microsoft/TypeScript · GitHub
Open Graph Title: Conditional type does not narrow union type · Issue #29188 · microsoft/TypeScript
X Title: Conditional type does not narrow union type · Issue #29188 · microsoft/TypeScript
Description: TypeScript Version: 3.2.2 Search Terms: conditional types, unions, narrowing Code interface A = { [key in keyof...
Open Graph Description: TypeScript Version: 3.2.2 Search Terms: conditional types, unions, narrowing Code interface A X Description: TypeScript Version: 3.2.2 Search Terms: conditional types, unions, narrowing Code interface A<T> { value: T; } interface Specification { [key: string]: Array<any> | Specification; } typ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/29188
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Conditional type does not narrow union type","articleBody":"**TypeScript Version:** 3.2.2\r\n\r\n**Search Terms:** conditional types, unions, narrowing\r\n\r\n**Code**\r\n\r\n```ts\r\n interface A\u003cT> {\r\n value: T;\r\n }\r\n\r\n interface Specification {\r\n [key: string]: Array\u003cany> | Specification;\r\n }\r\n\r\n type Mapping\u003cS extends Specification> = {\r\n [key in keyof S]: S[key] extends Array\u003cinfer T> ? A\u003cT> : Mapping\u003cS[key]>\r\n // Error ^^^^^^\r\n // Type 'S[key]' does not satisfy the constraint 'Specification'.\r\n // Type 'Specification[key]' is not assignable to type 'Specification'.\r\n // Type 'any[] | Specification' is not assignable to type 'Specification'.\r\n // Type 'any[]' is not assignable to type 'Specification'.\r\n // Index signature is missing in type 'any[]'.\r\n };\r\n```\r\n\r\n**Expected behavior:**\r\nNo error. \"Leafs\" of the `Specification` tree, which have type `Array\u003cT>` (for some `T`) should be mapped to `A\u003cT>`, while non-leaf properties should be recursively mapped.\r\n\r\n**Actual behavior:**\r\nIn the right-hand side of the conditional type, `S[key]` is not narrowed to `Specification`, even if the complete type of `S[key]` is `Array\u003cany> | Specification` and the `Array\u003cany>` case is catched in the left-hand side.\r\n\r\n**Playground Link:** [link](http://www.typescriptlang.org/play/#src=%0D%0Ainterface%20A%3CT%3E%20%7B%0D%0A%20%20%20%20value%3A%20T%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20Specification%20%7B%0D%0A%20%20%20%20%5Bkey%3A%20string%5D%3A%20Array%3Cany%3E%20%7C%20Specification%3B%0D%0A%7D%0D%0A%0D%0Atype%20Mapping%3CS%20extends%20Specification%3E%20%3D%20%7B%0D%0A%20%20%20%20%5Bkey%20in%20keyof%20S%5D%3A%20S%5Bkey%5D%20extends%20Array%3Cinfer%20T%3E%20%3F%20A%3CT%3E%20%3A%20Mapping%3CS%5Bkey%5D%3E%0D%0A%7D%3B%0D%0A)\r\n\r\n**Related Issues**: some similar issues related to conditional types, but I'm not sure whether this is a duplicate of any of them.\r\n","author":{"url":"https://github.com/lodo1995","@type":"Person","name":"lodo1995"},"datePublished":"2018-12-28T15:39:59Z","url":"https://github.com/microsoft/TypeScript/issues/29188"}
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:7961dc68-0fb8-ca2c-ff4f-9e318285ceba current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id EA48:3DF0BE:91818F:BE31CE:6B00E1B5 html-safe-nonce cd7e6fff1d6dd29db4a6934a9fea73fe7d8cf2e6059600edd8056b8d91941b50 visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTQ4OjNERjBCRTo5MTgxOEY6QkUzMUNFOjZCMDBFMUI1IiwidmlzaXRvcl9pZCI6IjYwNjQyODUwODgzMzY2MzQyOTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== visitor-hmac f3691e9d1a5b55bca9a073a7e99605849b55c70ef8910e8fb3abbac5e0b67c27 hovercard-subject-tag issue:394662927 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/29188/issue_layout twitter:image https://opengraph.githubassets.com/60a56d9ac945e5eaa0adc4f24e512aa52fa6fbcdb4438bc911a5be09bb54efc0/microsoft/TypeScript/issues/29188 twitter:card summary_large_image og:image https://opengraph.githubassets.com/60a56d9ac945e5eaa0adc4f24e512aa52fa6fbcdb4438bc911a5be09bb54efc0/microsoft/TypeScript/issues/29188 og:image:alt TypeScript Version: 3.2.2 Search Terms: conditional types, unions, narrowing Code interface A og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username lodo1995 hostname github.com expected-hostname github.com None 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf 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 5425dc24e8bd8d6fca9641a12afc984825a43875 ui-target full theme-color #1e2327 color-scheme light dark react-app-name issues
URLs of crawlers that visited me.