You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this example we are trying to compose the result of getCodecFromSerialized with JsonFromString. The error makes it difficult to spot which member codec is the culprit.
import*asSumfrom'@unsplash/sum-types';import{getCodecFromSerialized}from'@unsplash/sum-types-io-ts';import*astfrom'io-ts';import{JsonFromString}from'io-ts-types';typeMyUnion=|Sum.Member<'A',string>|Sum.Member<'B',string>|Sum.Member<'C',string|undefined>;constMyUnion=Sum.create<MyUnion>();constCodec=getCodecFromSerialized(MyUnion)({A: t.string,B: t.string,C: t.union([t.string,t.undefined]),});constCodecFromString=JsonFromString.pipe(// Error: Type 'readonly ["A", string] | readonly ["B", string] | readonly ["C", string | undefined]' is not assignable to type 'Json'.Codec,);
If getCodecFromSerialized required Json as the output type of all member codecs, we would have a much nicer error message:
constCodec=getCodecFromSerialized(MyUnion)({A: t.string,B: t.string,// Type 'undefined' is not assignable to type 'Json'.C: t.union([t.string,t.undefined]),});
The text was updated successfully, but these errors were encountered:
"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:
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:The text was updated successfully, but these errors were encountered: