Title: Long conditional type resolves to any · Issue #28663 · microsoft/TypeScript · GitHub
Open Graph Title: Long conditional type resolves to any · Issue #28663 · microsoft/TypeScript
X Title: Long conditional type resolves to any · Issue #28663 · microsoft/TypeScript
Description: TypeScript Version: 3.3.0-dev.20181122 Search Terms: conditional type resolves any Code After adding exactly this many conditions, the type of WrappedJsxNodeType will be any. import * as ts from "typescript"; type WrappedNodeType = Compi...
Open Graph Description: TypeScript Version: 3.3.0-dev.20181122 Search Terms: conditional type resolves any Code After adding exactly this many conditions, the type of WrappedJsxNodeType will be any. import * as ts from "t...
X Description: TypeScript Version: 3.3.0-dev.20181122 Search Terms: conditional type resolves any Code After adding exactly this many conditions, the type of WrappedJsxNodeType will be any. import * as ts from &q...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/28663
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Long conditional type resolves to any","articleBody":"**TypeScript Version:** 3.3.0-dev.20181122\r\n\r\n**Search Terms:** conditional type resolves any\r\n\r\n**Code**\r\n\r\nAfter adding exactly this many conditions, the type of `WrappedJsxNodeType` will be `any`.\r\n\r\n```ts\r\nimport * as ts from \"typescript\";\r\n\r\ntype WrappedNodeType = CompilerNodeToWrappedType\u003cts.JsxExpression>;\r\n\r\ntype CompilerNodeToWrappedType\u003cT extends ts.Node> = T extends ts.ArrayBindingPattern ? ArrayBindingPattern :\r\n T extends ts.BindingElement ? BindingElement :\r\n T extends ts.ObjectBindingPattern ? ObjectBindingPattern :\r\n T extends ts.ClassDeclaration ? ClassDeclaration :\r\n T extends ts.ClassExpression ? ClassExpression :\r\n T extends ts.ConstructorDeclaration ? ConstructorDeclaration :\r\n T extends ts.GetAccessorDeclaration ? GetAccessorDeclaration :\r\n T extends ts.MethodDeclaration ? MethodDeclaration :\r\n T extends ts.PropertyDeclaration ? PropertyDeclaration :\r\n T extends ts.SetAccessorDeclaration ? SetAccessorDeclaration :\r\n T extends ts.ComputedPropertyName ? ComputedPropertyName :\r\n T extends ts.Identifier ? Identifier :\r\n T extends ts.QualifiedName ? QualifiedName :\r\n T extends ts.SyntaxList ? SyntaxList :\r\n T extends ts.Decorator ? Decorator :\r\n T extends ts.JSDoc ? JSDoc :\r\n T extends ts.JSDocAugmentsTag ? JSDocAugmentsTag :\r\n T extends ts.JSDocClassTag ? JSDocClassTag :\r\n T extends ts.JSDocParameterTag ? JSDocParameterTag :\r\n T extends ts.JSDocPropertyTag ? JSDocPropertyTag :\r\n T extends ts.JSDocReturnTag ? JSDocReturnTag :\r\n T extends ts.JSDocTypedefTag ? JSDocTypedefTag :\r\n T extends ts.JSDocTypeTag ? JSDocTypeTag :\r\n T extends ts.JSDocUnknownTag ? JSDocUnknownTag :\r\n T extends ts.EnumDeclaration ? EnumDeclaration :\r\n T extends ts.EnumMember ? EnumMember :\r\n T extends ts.AsExpression ? AsExpression :\r\n T extends ts.AwaitExpression ? AwaitExpression :\r\n T extends ts.CallExpression ? CallExpression :\r\n T extends ts.CommaListExpression ? CommaListExpression :\r\n T extends ts.ConditionalExpression ? ConditionalExpression :\r\n T extends ts.DeleteExpression ? DeleteExpression :\r\n T extends ts.ImportExpression ? ImportExpression :\r\n T extends ts.MetaProperty ? MetaProperty :\r\n T extends ts.NewExpression ? NewExpression :\r\n T extends ts.NonNullExpression ? NonNullExpression :\r\n T extends ts.OmittedExpression ? OmittedExpression :\r\n T extends ts.ParenthesizedExpression ? ParenthesizedExpression :\r\n T extends ts.PartiallyEmittedExpression ? PartiallyEmittedExpression :\r\n T extends ts.PostfixUnaryExpression ? PostfixUnaryExpression :\r\n T extends ts.PrefixUnaryExpression ? PrefixUnaryExpression :\r\n T extends ts.SpreadElement ? SpreadElement :\r\n T extends ts.SuperElementAccessExpression ? SuperElementAccessExpression :\r\n T extends ts.SuperExpression ? SuperExpression :\r\n T extends ts.SuperPropertyAccessExpression ? SuperPropertyAccessExpression :\r\n T extends ts.ThisExpression ? ThisExpression :\r\n T extends ts.TypeAssertion ? TypeAssertion :\r\n T extends ts.TypeOfExpression ? TypeOfExpression :\r\n T extends ts.VoidExpression ? VoidExpression :\r\n T extends ts.JsxExpression ? JsxExpression : Node\u003cT>;\r\n\r\nclass Node\u003cNodeType extends ts.Node = ts.Node> {\r\n compilerNode!: NodeType;\r\n}\r\n\r\nclass JsxExpression extends Node\u003cts.JsxExpression> {}\r\nclass ArrayBindingPattern extends Node\u003cts.ArrayBindingPattern> {}\r\nclass BindingElement extends Node\u003cts.BindingElement> {}\r\nclass ObjectBindingPattern extends Node\u003cts.ObjectBindingPattern> {}\r\nclass ClassDeclaration extends Node\u003cts.ClassDeclaration> {}\r\nclass ClassExpression extends Node\u003cts.ClassExpression> {}\r\nclass ConstructorDeclaration extends Node\u003cts.ConstructorDeclaration> {}\r\nclass GetAccessorDeclaration extends Node\u003cts.GetAccessorDeclaration> {}\r\nclass MethodDeclaration extends Node\u003cts.MethodDeclaration> {}\r\nclass PropertyDeclaration extends Node\u003cts.PropertyDeclaration> {}\r\nclass SetAccessorDeclaration extends Node\u003cts.SetAccessorDeclaration> {}\r\nclass ComputedPropertyName extends Node\u003cts.ComputedPropertyName> {}\r\nclass Identifier extends Node\u003cts.Identifier> {}\r\nclass QualifiedName extends Node\u003cts.QualifiedName> {}\r\nclass SyntaxList extends Node\u003cts.SyntaxList> {}\r\nclass Decorator extends Node\u003cts.Decorator> {}\r\nclass JSDoc extends Node\u003cts.JSDoc> {}\r\nclass JSDocAugmentsTag extends Node\u003cts.JSDocAugmentsTag> {}\r\nclass JSDocClassTag extends Node\u003cts.JSDocClassTag> {}\r\nclass JSDocParameterTag extends Node\u003cts.JSDocParameterTag> {}\r\nclass JSDocPropertyTag extends Node\u003cts.JSDocPropertyTag> {}\r\nclass JSDocReturnTag extends Node\u003cts.JSDocReturnTag> {}\r\nclass JSDocTypedefTag extends Node\u003cts.JSDocTypedefTag> {}\r\nclass JSDocTypeTag extends Node\u003cts.JSDocTypeTag> {}\r\nclass JSDocUnknownTag extends Node\u003cts.JSDocUnknownTag> {}\r\nclass EnumDeclaration extends Node\u003cts.EnumDeclaration> {}\r\nclass EnumMember extends Node\u003cts.EnumMember> {}\r\nclass AsExpression extends Node\u003cts.AsExpression> {}\r\nclass AwaitExpression extends Node\u003cts.AwaitExpression> {}\r\nclass CallExpression extends Node\u003cts.CallExpression> {}\r\nclass CommaListExpression extends Node\u003cts.CommaListExpression> {}\r\nclass ConditionalExpression extends Node\u003cts.ConditionalExpression> {}\r\nclass DeleteExpression extends Node\u003cts.DeleteExpression> {}\r\nclass ImportExpression extends Node\u003cts.ImportExpression> {}\r\nclass MetaProperty extends Node\u003cts.MetaProperty> {}\r\nclass NewExpression extends Node\u003cts.NewExpression> {}\r\nclass NonNullExpression extends Node\u003cts.NonNullExpression> {}\r\nclass OmittedExpression extends Node\u003cts.OmittedExpression> {}\r\nclass ParenthesizedExpression extends Node\u003cts.ParenthesizedExpression> {}\r\nclass PartiallyEmittedExpression extends Node\u003cts.PartiallyEmittedExpression> {}\r\nclass PostfixUnaryExpression extends Node\u003cts.PostfixUnaryExpression> {}\r\nclass PrefixUnaryExpression extends Node\u003cts.PrefixUnaryExpression> {}\r\nclass SpreadElement extends Node\u003cts.SpreadElement> {}\r\nclass SuperElementAccessExpression extends Node\u003cts.SuperElementAccessExpression> {}\r\nclass SuperExpression extends Node\u003cts.SuperExpression> {}\r\nclass SuperPropertyAccessExpression extends Node\u003cts.SuperPropertyAccessExpression> {}\r\nclass ThisExpression extends Node\u003cts.ThisExpression> {}\r\nclass TypeAssertion extends Node\u003cts.TypeAssertion> {}\r\nclass TypeOfExpression extends Node\u003cts.TypeOfExpression> {}\r\nclass VoidExpression extends Node\u003cts.VoidExpression> {}\r\n```\r\n\r\nIf you remove the first condition in the type alias (`T extends ts.ArrayBindingPattern ? ArrayBindingPattern :`) you will see it correctly resolve to `JsxExpression`.\r\n\r\n**Expected behavior:** Resolves to `JsxExpression`\r\n\r\n**Actual behavior:** Resolves to `any`.\r\n\r\nI was code generating all this with ts-simple-ast until it failed ([see here](https://gist.github.com/dsherret/499c61da33570f9ba8efda924e49ec64)), so I tried randomly shuffling the array of type names I was generating it with to see if what was in the conditions mattered, but it always seemed to fail after 51 classes. (Edit: Updated example to step through the array of nodes and they all fail at 51 classes. Actually, in some cases when shuffling it would differ, but that was just because it happened to match a base type.)\r\n\r\nMy declaration files keep being generated with `any` types and occasionally objects I use internally are typed as `any` because of this issue. Perhaps there's a better way I can do this mapping? Thanks!\r\n","author":{"url":"https://github.com/dsherret","@type":"Person","name":"dsherret"},"datePublished":"2018-11-24T17:00:53Z","url":"https://github.com/microsoft/TypeScript/issues/28663"}
| 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:e1290c46-7ab3-f5fe-f860-a250e31733fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E0F8:2F543F:77994B:9EA437:6B01AAD4 |
| html-safe-nonce | a383b5668f585b8f49b580293fea523259faa51961861d8e1e7d54945ebeec24 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMEY4OjJGNTQzRjo3Nzk5NEI6OUVBNDM3OjZCMDFBQUQ0IiwidmlzaXRvcl9pZCI6IjIyNDczODQ3MDA3NjkzODEwNzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0fec39c50defccc0bb7f6d7777b5d1a27c32269f079aa4bc51a81186393ac9b3 |
| hovercard-subject-tag | issue:384004930 |
| 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/28663/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a9a3a971724e5f4c40200a199109927bf8508de7ce110990e326e48c969942ea/microsoft/TypeScript/issues/28663 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a9a3a971724e5f4c40200a199109927bf8508de7ce110990e326e48c969942ea/microsoft/TypeScript/issues/28663 |
| og:image:alt | TypeScript Version: 3.3.0-dev.20181122 Search Terms: conditional type resolves any Code After adding exactly this many conditions, the type of WrappedJsxNodeType will be any. import * as ts from "t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dsherret |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width