typebox
typebox copied to clipboard
Feature request: functions as defaults
I'd like to be able to use functions as defaults so that they can run when Value.Create is used.
// Desired syntax:
export const FileSchema = Type.Object({
id: Type.String({ default: () => ulid() }), // arrow func
createdDate: Type.Number({ default: Date.now }), // non-invoked function reference
});
// Later
Value.Create(FileSchema) // the defaults evaluate now
Desired behavior: defaults are evaluated at Value.Create time if they're a function Actual behavior: fields with a function as default are dropped from the created object with no error or warning