You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wonder if when we’re trying to see if the base constraint is an array, we can just say “no” without issuing a circularity error if we hit a circularity.
The issue is that when we discover a circularity, we record that fact (and issue an error), and the type in question will then appear to have no constraint. Basically, we need to check if attempting to resolve the constraint would cause a circularity and, if so, not obtain the constraint. But we're not equipped to do such a check--at least not without revising a number of code paths.
Because you'd have to thread that through a whole bunch of different code paths so that you don't cache anything for any of the other resolutions that were part of forming the circle.
The alternative to my PR is just to have another overload on Promise.all that takes any. Overload resolution goes through an initial pass using the subtype relationship so that an any doesn't succeed with the first overload.
The question is whether we could always guarantee that the any overload goes last - I don't think we try to guarantee any ordering of lib.d.ts.
Activity
sandersn commentedon Oct 29, 2021
Uh, here it is:
That looks circular to me. But 4.4 doesn't complain about it.
andrewbranch commentedon Oct 29, 2021
I wonder if when we’re trying to see if the base constraint is an array, we can just say “no” without issuing a circularity error if we hit a circularity.
ahejlsberg commentedon Oct 29, 2021
The issue is that when we discover a circularity, we record that fact (and issue an error), and the type in question will then appear to have no constraint. Basically, we need to check if attempting to resolve the constraint would cause a circularity and, if so, not obtain the constraint. But we're not equipped to do such a check--at least not without revising a number of code paths.
andrewbranch commentedon Oct 29, 2021
Why can't we just add a parameter to
getResolvedBaseConstraintthat, upon discovering the circularity, bails instead of erroring and caching?ahejlsberg commentedon Oct 29, 2021
Because you'd have to thread that through a whole bunch of different code paths so that you don't cache anything for any of the other resolutions that were part of forming the circle.
andrewbranch commentedon Oct 29, 2021
Ah, I missed that almost everything that
computeBaseConstraintcalls does its own caching 😕ahejlsberg commentedon Oct 29, 2021
Yup. However, I think I have a simpler solution. We can use a check of the form
to detect if we're already in the process of obtaining the constraint of the type variable, and, if so, skip the array check.
DanielRosenwasser commentedon Oct 29, 2021
The alternative to my PR is just to have another overload on
Promise.allthat takesany. Overload resolution goes through an initial pass using the subtype relationship so that ananydoesn't succeed with the first overload.The question is whether we could always guarantee that the
anyoverload goes last - I don't think we try to guarantee any ordering oflib.d.ts.andrewbranch commentedon Oct 29, 2021
Also possible workaround for the type definitions:
ahejlsberg commentedon Oct 29, 2021
The solution I proposed above appears to fix it. Just running tests now to see that it doesn't affect anything else.