Handling Default Values in Encoded Schemas

Hi! Might be a stupid question but I'm having trouble with default values / constructors in Schema.

I have the following schema where I would want dueDate to have a default value of the current date. This works when making an instance of Chore (I see a DateTime object being created with the current date).

However, what I pass to my frontend is ChoreEncoded. This way there are no options / DateTime objects, they are all optional properties & plain strings, since this plays nice with <input> elements. However when the form is instantiated client-side, dueDate is undefined!

How do I define a default value for it? I basically want the same constructor as the original Chore, but where the DateTime is encoded to a string. Is this possible?
export type Chore = Schema.Schema.Type<typeof Chore>;
export type ChoreEncoded = Schema.Schema.Encoded<typeof Chore>;
export const ChoreId = Schema.String;

export const Chore = Schema.Struct({
    id: ChoreId,
    name: Schema.String,
    assignedTo: PersonFromId,
    dueDate: Schema.DateTimeUtc.pipe(
        Schema.propertySignature,
        Schema.withConstructorDefault(() => DateTime.unsafeNow()),
    ),
    repeat: Schema.DurationFromMillis.pipe(Schema.OptionFromUndefinedOr),
    completed: Schema.Boolean,
});

export const ChoreEncoded = Schema.encodedSchema(Chore);
Was this page helpful?