Open pbarbiero opened 3 years ago
@ianstormtaylor I am not a TS developer, and this is probably less elegant than you'd like, but this does resolve it for me:
// https://github.com/ianstormtaylor/superstruct/blob/main/src/structs/utilities.ts#L55
function assign(...Structs) {
const isType = Structs[0].type === 'type';
const schemas = Structs.map(s => s.schema);
const coercers = Structs.map(s => s.coercer);
const schema = Object.assign({}, ...schemas);
const mergedSchema = isType ? type(schema) : object(schema);
mergedSchema.coercer = (...args) => ({
...Object.assign({}, ...coercers.map(coercer => coercer(...args))),
});
return mergedSchema;
}
Wrapping a struct using
defaulted
withassign
causes coercion to no longer work.Easy enough test:
Expected result: coercer still works