Closed benj-dobs closed 2 years ago
If I return undefined from a coercion, the coercion is ignored completely, and the original value is kept (even if the original value does not satisfy the struct we're coercing the value into).
undefined
The most common use case in my project is:
const coercableOptional = <T>(struct: Struct<T>) => coerce(optional(struct), literal(null), () => undefined);
This no longer works: null values are retained, even if struct should not allow null values.
null
struct
I think this was caused by #1106
Is there an alternative syntax for coercing to undefined, or is this a bug that needs fixing?
I'm more and more convinced this is a bug, and I've raised a pull request to fix it. Let me know if I've got that wrong :)
If I return
undefined
from a coercion, the coercion is ignored completely, and the original value is kept (even if the original value does not satisfy the struct we're coercing the value into).The most common use case in my project is:
This no longer works:
null
values are retained, even ifstruct
should not allow null values.I think this was caused by #1106
Is there an alternative syntax for coercing to undefined, or is this a bug that needs fixing?