I stumbled across a seemingly simple example where Describe does not work well with union. However, it might be I am missing something.
Consider the following:
type A = {
a: "a";
};
type B = {
b: "b";
};
const aStruct: Describe<A> = object({
a: literal("a"),
});
const bStruct: Describe<B> = object({
b: literal("b"),
});
const aorbStruct: Describe<A | B> = union([aStruct, bStruct]);
I would expect this to work. However, aorbStruct shows a TS error:
TS2322: Type Struct<A | B, null> is not assignable to type Describe<A | B>
Types of property schema are incompatible.
Type null is not assignable to type
{
a: Describe<"a">;
} | {
b: Describe<"b">;
}
The strange thing is that it works once I include a primitive in the union:
Hi everyone,
I stumbled across a seemingly simple example where
Describe
does not work well withunion
. However, it might be I am missing something.Consider the following:
I would expect this to work. However,
aorbStruct
shows a TS error:The strange thing is that it works once I include a primitive in the union:
works fine.
Could you please
const aorbStruct: Describe<A | B> = union([aStruct, bStruct]);
case workingThank you!