Open OliverJAsh opened 6 months ago
"Serialized" in sum-types really just means unwrapping the object with its symbols to a plain tuple, giving you the raw data in its least opinionated form. I think that's appropriate as other forms of end-to-end serialization exist besides JSON.
Given this example the second line of the error is a bit narrower:
const ab: Json = null as any as ["A", string] | ["B", undefined]
Type '["A", string] | ["B", undefined]' is not assignable to type 'Json'.
Type '["B", undefined]' is not assignable to type 'Json'.
Given this is likely a common use case then a getCodecFromJSON
would probably make sense.
In this example we are trying to compose the result of
getCodecFromSerialized
withJsonFromString
. The error makes it difficult to spot which member codec is the culprit.If
getCodecFromSerialized
requiredJson
as the output type of all member codecs, we would have a much nicer error message: