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
you have 2 instantiations: the outer conditional type and the union in the true branch.
Means you can only get 24 characters deep before TypeScript gives you a 😢.
Other alternatives:
generators - slow, ugly output
explicit stack management - not a totally natural fit
Risks:
More memory usage
Slower non-termination of infinitely expanding types.
Can impact the language service.
Conservative estimate of about 100 bytes per stack frame.
Ball-parked from playing around with examples, but is variable.
Have we played with non-V8 engines?
Not much.
Does Safari do any better? It implements Tail Call Optimization
But our instantiation logic is not tail-recursive (even when instantiating a tail-recursive type).
There are certian places where functions hand off directly to another function though - in certain cases, yes, that would help - but only as far as inlining would help.
Concerns around LS still hold - but instantiationCount limit on source elements helps a bit.
But our instantiation logic is not tail-recursive (even when instantiating a tail-recursive type).
Perhaps implementing tail-call optimisation for types is worth investigating? It won't cover all problem cases, but perhaps it'll be good enough for most recursive transforms people are using?
FWIW I generally try to write my recursive types in a tail-recursive manner anyway, so it would definitely help me! 😄
Increasing the Type Instantiation Depth Limit
#45025
People keep doing more and more advanced patterns in type-space; the instantiation depth limiter is too low for these scenarios.
For creating a union of characters as in the PR,
you have 2 instantiations: the outer conditional type and the union in the true branch.
Other alternatives:
Risks:
Conservative estimate of about 100 bytes per stack frame.
Have we played with non-V8 engines?
Concerns around LS still hold - but
instantiationCount
limit on source elements helps a bit.https://github.com/microsoft/TypeScript/blob/541e553163bb79fba64fdfd7c8a2c96f201c3b0a/src/compiler/checker.ts#16255
Making the instantiation depth configurable?
Shipping this in 4.5?
Can we message this as a "be cautious about relying strongly on this behavior" in the release notes?
Could try type-call elimination to avoid blowing our own stack.
Auto-Imports and the
node:
Prefix#43842
Contextually Typing IIFEs
#44992
#45007
async
function!Import Assertions
#40698
The text was updated successfully, but these errors were encountered: