Let's say we have a struct with field that accepts multiple literals. I want to decode it in a way, that if the decoding of the field fails, the
unknown
unknown
is set as a value.
I was used to doing it in a zod like this:
const zodObject = z.object({ someLiterals: z.enum(['valueA', 'valueB', 'unknown']).catch('unknown'), // ... imagine there are more fields here})const schemaObject = Schema.Struct({ someLiterals: Schema.Literal('valueA', 'valueB', 'unknown'), // How to catch errors, if there is an unknown value? // ...imagine there are more fields here})
const zodObject = z.object({ someLiterals: z.enum(['valueA', 'valueB', 'unknown']).catch('unknown'), // ... imagine there are more fields here})const schemaObject = Schema.Struct({ someLiterals: Schema.Literal('valueA', 'valueB', 'unknown'), // How to catch errors, if there is an unknown value? // ...imagine there are more fields here})
So object like this
{someLiterals: 'valueC'}
{someLiterals: 'valueC'}
gets encoded into
{someLiterals: 'unknown'}
{someLiterals: 'unknown'}
.
Is it possible to do with some transformer in schema?