So I have the following type A, descriminated by the property ‘type’:
type A = { type: 'x', foo: boolean } | { type: 'y', bar: string }
with this type I can make objects such as
{
type: 'x',
foo: false
}
or
{
type: 'y',
bar: "hmm"
}
and I have a type B, which takes the { type: ‘x’ } discriminated union from A, and allows for an extra baz
type B = Extract<A, { type: 'x' }> & { baz: number }
This type B will allow for objects such as
{
type: 'x'
foo: false,
baz: 3
}
Now, I want to merge this B back into another type, that will basically overwrite the union discriminated by ‘x’ with the definition from B, but leave the original ‘type: y’ from A intact. So like
{
type: 'x'
foo: false,
baz: 3
}
or
{
type: 'y',
bar: "hmm"
}