Effect CommunityEC
Effect Community17mo ago
19 replies
cmbntr

Example for recursive sum type schema?

How can a recursive sum type be represented in Schema?

The existing documentation example for mutually recursive schemas is about a struct product type (Expression and Operation). The example suggests to define Typescript interfaces for the Schema types first and use them as type annotations in the Schema.suspend calls.

How can these types be expressed in Schema?
type JSONObject = { [key: string] : JSONValue }
type JSONArray = JSONValue[]
type JSONValue = string | number |  boolean | null | JSONObject | JSONArray


Use Case: I have a “slot” in my data structure which should just hold a valid JSON value as returned by JSON.parse(). The existing Schema.Any is too open for this use case.
Was this page helpful?