Declaring Fallback Values for Unknown Literals
What is the best way to declare fallback values for unknown literals? I'm tackling the problem of ensuring forward-compatibility of schemas and often I face literal values that may be extended in the future. For example:
The workaround is suboptimal for the following reasons:
- Parsing succeeds even if
- Only works if there is a parent object in which the schema can be placed,
I'd like to hear from you. How do you tackle forward-compatibility with schema? Am I just not aware of some API?
const planType = Schema.literal("lite", "professional", "enterprise"). Let's say someone introduces a new plan type enterprise-plus. I would not want the parsing of this schema to fail. The way I'm currently solving it is the following:The workaround is suboptimal for the following reasons:
- Parsing succeeds even if
planType is missing or undefined, some schema users may want it to fail in such a case- Only works if there is a parent object in which the schema can be placed,
Schema.literal does not have a withDefault method on it.I'd like to hear from you. How do you tackle forward-compatibility with schema? Am I just not aware of some API?
