-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Long conditional type resolves to any #28663
Comments
What happens if you change them all to be, | (T extends ts.ThisExpression ? ThisExpression : never)
| (T extends ts.PropertyAccessExpression ? PropertyAccessExpression : never)
//etc.
//etc.
//etc. So, instead of chaining conditional types, you make it a union of conditional types. |
Haaaaaaah, this type quietly hits the instantion depth limit we added all on it's own. 50 miiiight be too low if machine-generated types are kept in mind. |
@ahejlsberg think we can increase the limit or be smarter about what we count so structures like this type-based case block can actually work? |
Oh yeah, you're right that it's just a depth of 50. Here's a type with no dependencies that shows the behaviour (generated via this code): type ToString<T> = T extends 51 ? "51" :
T extends 50 ? "50" :
T extends 49 ? "49" :
T extends 48 ? "48" :
T extends 47 ? "47" :
T extends 46 ? "46" :
T extends 45 ? "45" :
T extends 44 ? "44" :
T extends 43 ? "43" :
T extends 42 ? "42" :
T extends 41 ? "41" :
T extends 40 ? "40" :
T extends 39 ? "39" :
T extends 38 ? "38" :
T extends 37 ? "37" :
T extends 36 ? "36" :
T extends 35 ? "35" :
T extends 34 ? "34" :
T extends 33 ? "33" :
T extends 32 ? "32" :
T extends 31 ? "31" :
T extends 30 ? "30" :
T extends 29 ? "29" :
T extends 28 ? "28" :
T extends 27 ? "27" :
T extends 26 ? "26" :
T extends 25 ? "25" :
T extends 24 ? "24" :
T extends 23 ? "23" :
T extends 22 ? "22" :
T extends 21 ? "21" :
T extends 20 ? "20" :
T extends 19 ? "19" :
T extends 18 ? "18" :
T extends 17 ? "17" :
T extends 16 ? "16" :
T extends 15 ? "15" :
T extends 14 ? "14" :
T extends 13 ? "13" :
T extends 12 ? "12" :
T extends 11 ? "11" :
T extends 10 ? "10" :
T extends 9 ? "9" :
T extends 8 ? "8" :
T extends 7 ? "7" :
T extends 6 ? "6" :
T extends 5 ? "5" :
T extends 4 ? "4" :
T extends 3 ? "3" :
T extends 2 ? "2" :
"1";
type Result = ToString<1>; It would be nice to be warned about this behaviour in some way (maybe resolve to an |
Just following up on this and it no longer affects me. @Gerrit0 helped me out and I managed to shorten my conditional type to the type shown in this post: dsherret/ts-morph#507 (comment) This works in my situation because of the |
With #29435 we now report an error on instantiations that are over 50 levels deep instead of silently resolving to |
In #29511 , I had problems with the instantiation depth. I've opened up a PR #29602 to add a compiler option to increase the max depth. The library I'm working on, here (v3 branch is the only good branch), doesn't run into the limit. But projects that use it would probably run into the depth limit after having deeply nested expressions. Of course, the best thing to do would be to not have such complicated types in the first place but, I think, in my case, I couldn't help it because I'm checking MySQL queries for validity during compile time. |
@ahejlsberg thanks! Being warned about this limit is much better. When I first encountered it I just assumed the language service was having a moment and the problem remained in the library for several months. Anyway, doesn't affect me anymore, but I can imagine it will affect others down the road (https://twitter.com/andygocke/status/1067488906763878400). |
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 beany
.If you remove the first condition in the type alias (
T extends ts.ArrayBindingPattern ? ArrayBindingPattern :
) you will see it correctly resolve toJsxExpression
.Expected behavior: Resolves to
JsxExpression
Actual behavior: Resolves to
any
.I was code generating all this with ts-simple-ast until it failed (see here), 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.)
My declaration files keep being generated with
any
types and occasionally objects I use internally are typed asany
because of this issue. Perhaps there's a better way I can do this mapping? Thanks!The text was updated successfully, but these errors were encountered: