Hey,
Zod allows for the use of default value. It can be useful when for example, I'm adding a new field to a zod schema, that may not be present in older documents, and that I do not necessarily need to add to all the previous doc. Instead, I'm using .default from zod to give it a default value for case where the value's not present in the document.
This is a Zod exclusive feature, and was wondering how TypeSync could support it, since YAML is used for the definition. This .default value allows either literal type, or even plain JavaScript object (like new Date()), or at runtime with a function. So I am not sure how this could be properly implemented in TypeSync. I guess we could just have static values
For now, I will probably simply add it manually after I generated all my types, by adding the .default to previously generated field.
Like so:
EmployeeSchema.extend({ firstName: EmployeeSchema.shape.firstName.default("John") })
Thanks for your work and quick responses! This is a promising project that would help tons of project!
Hey,
Zod allows for the use of default value. It can be useful when for example, I'm adding a new field to a zod schema, that may not be present in older documents, and that I do not necessarily need to add to all the previous doc. Instead, I'm using .default from zod to give it a default value for case where the value's not present in the document.
This is a Zod exclusive feature, and was wondering how TypeSync could support it, since YAML is used for the definition. This .default value allows either literal type, or even plain JavaScript object (like new Date()), or at runtime with a function. So I am not sure how this could be properly implemented in TypeSync. I guess we could just have static values
For now, I will probably simply add it manually after I generated all my types, by adding the .default to previously generated field.
Like so:
Thanks for your work and quick responses! This is a promising project that would help tons of project!