Note that, on the one hand, this definition is correct.
On the other hand, it's also infinite. And since types
aren't tied to actual data, we don't have a type-level
"base case" we can fall back on.
In fact, the only reason our IDE doesn't start
slogging is because TypeScript compiler does extra work
to "cache" this type, and detect the circular reference.
While this type happens to work in this case, it's also brittle:
a small change in its definition could cause the TS compiler to
cache things differently, and we might wind up with a very
difference performance profile.
If you'd prefer to avoid this problem (and others like it), use
Json.Unary instead.
Json.Fixpoint
This type represents the what's called (to get math-y) the "fixpoint" of the Json Functor.
There are reasons to use
Json.Fixpoint
overJson.Unary
, and vice-versa.Note that, on the one hand, this definition is correct.
On the other hand, it's also infinite. And since types aren't tied to actual data, we don't have a type-level "base case" we can fall back on.
In fact, the only reason our IDE doesn't start slogging is because TypeScript compiler does extra work to "cache" this type, and detect the circular reference.
While this type happens to work in this case, it's also brittle: a small change in its definition could cause the TS compiler to cache things differently, and we might wind up with a very difference performance profile.
If you'd prefer to avoid this problem (and others like it), use
Json.Unary
instead.