-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Discriminated unions that are self-referential and any mutually recursive types are not supported. Using the $id and $ref keys in JSON should allow this type of structure to be serialized.
for a type definition like such:
type A = { B of B } and B = { A of A }
the json should end up being something like:
{
"A": {
"$id": "1",
"B": { "$ref": "2" }
},
"B": {
"$id": "2",
"A": { "$ref": "1" }
}
}
This is an incredibly simplified example, but there's an approach we can take using reflection to figure out what properties cause a cycle in a generic data structure. Once we've identified the cycle, we can use comparison of all other fields (excluding the cyclical part) to understand which records reference which other records.
I've included a first draft of a function to determine if a type is recursive or not.