We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrapping a struct using defaulted with assign causes coercion to no longer work.
defaulted
assign
Easy enough test:
const struct = defaulted( object({ id: string(), enabled: boolean(), }), { enabled: false, }, ); console.log(struct.coercer()); // { enabled: false } console.log(assign(struct).coercer()); // undefined
Expected result: coercer still works
The text was updated successfully, but these errors were encountered:
@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; }
Sorry, something went wrong.
No branches or pull requests
Wrapping a struct using
defaulted
withassign
causes coercion to no longer work.Easy enough test:
Expected result: coercer still works
The text was updated successfully, but these errors were encountered: