diff --git a/src/structs/types.ts b/src/structs/types.ts index 24000bf7..ba930abf 100644 --- a/src/structs/types.ts +++ b/src/structs/types.ts @@ -690,8 +690,8 @@ export function union( type: 'union', schema: null, coercer(value) { - for (const { validate } of Structs) { - const [error, coerced] = validate(value, { coerce: true }); + for (const InnerStruct of Structs) { + const [error, coerced] = InnerStruct.validate(value, { coerce: true }); if (!error) { return coerced; } diff --git a/src/utils.ts b/src/utils.ts index 305ae71d..282a0e74 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -199,7 +199,8 @@ export function* run( yield [failure, undefined]; } - for (const [innerKey, innerValue, innerStruct] of struct.entries( + // eslint-disable-next-line prefer-const + for (let [innerKey, innerValue, innerStruct] of struct.entries( value, context, )) { @@ -220,8 +221,7 @@ export function* run( yield [result[0], undefined]; } else if (coerce) { - // eslint-disable-next-line no-param-reassign - value = result[1]; + innerValue = result[1]; if (innerKey === undefined) { // eslint-disable-next-line no-param-reassign