Open effect-bot opened 3 weeks ago
In short I think it would make sense for Schema.partial() to convert the fields to PropertySignature
s if they aren't already. If the prop is already a property signature I would expect that the prop specific def would take precedence in order to allow assigning defaults, etc. In general however I would expect
Schema.Struct({
a: Schema.Number
}).pipe(Schema.partial({ nullable: true }))
to be equivalent to
Schema.Struct({
a: Schema.optional(Schema.Number, { nullable: true })
})
Summary
The conversation revolves around the need to simplify the process of making schema properties optional and nullable in the Effect-TS ecosystem. Jesse Kelly mentions using
Schema.partial(_, { nullable: true, as: "Option" })
to avoid manually writingSchema.optional(x, { nullable: true, as: "Optional" })
for each property, which can be cumbersome. Tylor agrees and mentions that he often uses a helper for the optional variant. Jesse Kelly further elaborates that being able to define theStruct.optional
configuration for every property at once would reduce boilerplate, especially for entirely partial structures or when dealing with separate RequiredProps and OptionalProps structs.Key Takeaways:
Discord thread
https://discord.com/channels/795981131316985866/1255872346267451402