79452115

Date: 2025-02-19 16:37:30
Score: 0.5
Natty:
Report link

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

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: user16717440