Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #7

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/structs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@ export function union<First extends AnyStruct, Rest extends AnyStruct[]>(
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 });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was broken because Struct.validate references this.

if (!error) {
return coerced;
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ export function* run<Type, Schema>(
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,
)) {
Expand All @@ -220,8 +221,7 @@ export function* run<Type, Schema>(

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
Expand Down
Loading