Open
Description
Instead of having to use S.union with S.attachPropertySignature directly to create tagged objects, a simpler solution might be to add a S.attachSignatures helper that fn that abstracts this behavior. The naming might not be the best but the idea is that the original api and the alternative api below produce identical schemas.
const Circle = S.struct({ radius: S.number });
const Square = S.struct({ sideLength: S.number });
// original api
const DiscriminatedShape = S.union(
Circle.pipe(S.attachPropertySignature("kind", "circle")),
Square.pipe(S.attachPropertySignature("kind", "square")),
);
// alternative (/complimentary) api
S.attachSignatures("kind", {
"circle": Circle,
"square": Square
})
Metadata
Metadata
Assignees
Type
Projects
Status
Created