Accessing Union Type Schema in TypeScript
Hey there! Assume that Schema;
How can I access / »derive« the Schema for the Unions »type« Property?
How can I access / »derive« the Schema for the Unions »type« Property?
const UnionFromString = S.transformOrFail(
S.String,
S.Union(
S.Struct({
type: S.Literal('a'),
a: S.Number
}),
S.Struct({
type: S.Literal('b'),
b: S.String
})
),
{
// Question here
decode: str => {
const type = str.slice(0,1);
// How can use the Unions Schema for the »type«
// property here in order decode it
},
encode: item => …
}
)