Open JQuezada0 opened 10 months ago
Hi @JQuezada0, thank you for opening this issue! As you've discovered, Typical does not currently support recursive types, and the schema validator actively detects and forbids them.
It would be nice to remove this restriction at some point, but supporting recursive types would require answers to some subtle questions. For example, in languages like Rust, where should the Box
be inserted? In your example, we could box either Foo.b
or FooOrBar.foo
, and it's not clear (to me) why one should be preferred over the other. Perhaps the user would need to explicitly annotate their decision in the schema?
I'll leave this issue open for further discussion.
One could perhaps borrow from the ML family and use a rec
keyword to declare the point at which recursion is accepted, and use that to determine the implementation-specific solution to allowing the recursion?
Yes!
First off, great framework! As someone who hasn't worked a lot with data interchange formats, I was surprised that the first formats I ran into didn't have both strict support for non-nullable types and ADTs.
Description I'm trying to define a recursive type, but it looks like it's not supported.
Schema:
I was hoping that making the field optional, or replacing a directly recursive field with a choice that allows the recursion to end would allow the codegen to succeed, but it looks like recursive types in any form will trigger the error.
Are there any thoughts / plans on supporting this? I could imagine having some ability to limit the depth, like Rust's
![recursion_limit = "512"]
.This would have to result in a
Box
on the rust side: PlaygroundTypescript
Alternatives considered The actual situation I'm working with is in modeling a type-check diagnostic result from typescript's compiler api. As a workaround, I've added another type which omits the recursive field, and will have to flatten out the data into a plain array
Typical
Taken from typescript 4.7.4 source code