The current way I have gotten around this is by using coerce
. This allows for transformation pre validation. Then when the invalid content is encountered it can be transformed into the correct one. You need to use create
instead of assert
though. The example is
const Struct = type({
parent: record(
string(),
coerce(type({ body: number() }), number(), (value) => ({ body: value })))
})
Unfortunately this still does not answer how to validate a partially dynamic type like this but still provides a work around at least