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
ssalbdivad3mo 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
SynthLuvrOP3mo ago
I'm pretty sure it worked in the past but I don't know when
ssalbdivad
ssalbdivad3mo 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
PIat3mo ago
What would an alternative way be?
ssalbdivad
ssalbdivad3mo 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
PIat3mo ago
So right now it's more of future-proofing?
ssalbdivad
ssalbdivad3mo 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
PIat3mo ago
What do you mean by nonsense and how come it's ideal if it's nonsense?
ssalbdivad
ssalbdivad3mo ago
Because the external inference is ideal, but internally it requires a lot of hoop-jumping
PIat
PIat3mo ago
I see! You're jumping all the hoops so that we have ideal inference 🤗
ssalbdivad
ssalbdivad3mo ago
Well that is essentially the entire premise of arktype 😛
PIat
PIat3mo ago
And man is the inference ideal
ssalbdivad
ssalbdivad3mo ago
Well I'm fixing some cases where it was not now haha
PIat
PIat3mo 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
ssalbdivad3mo ago
I wish I didn't have to but in is a reserved keyword
PIat
PIat3mo ago
Understood And so Out is also capitalized for consistency
ssalbdivad
ssalbdivad3mo ago
Yeah In other contexts e.g. as a property it's actually fine But you can't define it as a type like that So I just end up capitalizing it there rather than come up with a different name everywhere else when it's mostly ideal
PIat
PIat3mo ago
At the same time it plays well in the situation of tIn Rightttt
ssalbdivad
ssalbdivad3mo ago
tIn is actually gone now I renamed it to match those other methods inferBrandableIn Better that it's more descriptive
PIat
PIat3mo ago
Not infer.brandable.In?
ssalbdivad
ssalbdivad3mo ago
So that is the namespace type, but in terms of the prop attached to Type, it's better that you can access it shallowly because at a type-level t["infer"]["brandable"]["In"] is pretty painful to write 😛
PIat
PIat3mo ago
Got it! Yeah, that looks like my types haha I never created namespaces before
ssalbdivad
ssalbdivad3mo ago
Yeah they're really mostly just useful for organizing types to make them easily discoverable- mostly useful for library APIs
Dimava
Dimava3mo ago
Is there string.bigint.parse yet?
ssalbdivad
ssalbdivad3mo ago
No you should add it
PIat
PIat3mo ago
Got it, thank you 👍
SynthLuvr
SynthLuvrOP3mo ago
What would be cool is if we could do type("bigint>0n")
ssalbdivad
ssalbdivad3mo ago
Yeah compartors are one of the oldest parts of ArkType. When I was first building them, bigints weren't actually used very often so I didn't prioritize adding that syntax Would definitely accept an issue/PR though. It would be relatively achievable for an external contributor because it would just mirror the design of the other bound kinds
Want results from more Discord servers?
Add your server