Type instantiation is excessively deep and possibly infinite

const A = type("bigint").narrow(() => true).pipe((v) => v.toString());
type A = typeof A.in.infer;
const A = type("bigint").narrow(() => true).pipe((v) => v.toString());
type A = typeof A.in.infer;
Produces error:
Type instantiation is excessively deep and possibly infinite.
Type instantiation is excessively deep and possibly infinite.
28 Replies
ssalbdivad
ssalbdivad2w ago
Do you know if this is a regression/when it worked? This should be an easy one to fix at least. If it is only infinite when one side of the type is extracted, it's a bug in distill
SynthLuvr
SynthLuvr2w ago
I'm pretty sure it worked in the past but I don't know when
ssalbdivad
ssalbdivad2w ago
Yeah I made some changes recently to distill I'll fix this right away though Hmm there's really a whole set of narrowed inference that will fail if you infer out of a morph first which forces constrain<X, Y> to evaluate This is why I originally wanted constrain to not be a subtype of the original type but at some point it seemed like I could extract what I needed so I went with it. Once you have an intersection like string & {[constrained]: constraints} it is not possible to get back to string without enumerating all the possible builtins I want to check for which kinda sucks
PIat
PIat2w ago
What would an alternative way be?
ssalbdivad
ssalbdivad2w ago
Just have the constrained types be a tuple or something like [base, "constrain", constrained] But then they couldn't be used directly Not that they ever really are at the moment Morph types already work that way- they can't be used directly to represent the actual data
PIat
PIat2w ago
So right now it's more of future-proofing?
ssalbdivad
ssalbdivad2w ago
Well for now the branded types are always assignable to the base type I will keep it that way, I found some nonsense I can do to work around it Since obviously that is ideal But there's not really a builtin API for actually using the branded output types by default yet Maybe would be a global config at some point so you can choose if you want branded types But having the information encoded in the type opens up a lot of other possibilities also. The original reason I added it was to support pattern matching
PIat
PIat2w ago
What do you mean by nonsense and how come it's ideal if it's nonsense?
ssalbdivad
ssalbdivad2w ago
Because the external inference is ideal, but internally it requires a lot of hoop-jumping
PIat
PIat2w ago
I see! You're jumping all the hoops so that we have ideal inference 🤗
ssalbdivad
ssalbdivad2w ago
Well that is essentially the entire premise of arktype 😛
PIat
PIat2w ago
And man is the inference ideal
ssalbdivad
ssalbdivad2w ago
Well I'm fixing some cases where it was not now haha
PIat
PIat2w ago
Also I really like the new type.infer syntax What is the reasoning behind it being capitalized in type.infer.In and type.infer.Out?
ssalbdivad
ssalbdivad2w ago
I wish I didn't have to but in is a reserved keyword
Want results from more Discord servers?
Add your server