Skip to content

Commit

Permalink
Set ObjectType issue immediately on first unrecognized key
Browse files Browse the repository at this point in the history
  • Loading branch information
jviide committed Jan 21, 2025
1 parent d77d16f commit eabf924
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,11 @@ function createObjectMatcher(
if (flags & FLAG_FORBID_EXTRA_KEYS) {
if (unrecognized === undefined) {
unrecognized = [key];
issues = joinIssues(issues, {
ok: false,
code: "unrecognized_keys",
keys: unrecognized,
});
} else {
unrecognized.push(key);
}
Expand Down Expand Up @@ -1238,24 +1243,18 @@ function createObjectMatcher(
}
}

if (unrecognized !== undefined) {
return joinIssues(issues, {
ok: false,
code: "unrecognized_keys",
keys: unrecognized,
});
} else if (issues !== undefined) {
if (issues !== undefined) {
return issues;
} else {
if (checks !== undefined) {
for (const { func, issue } of checks) {
if (!func(output ?? obj)) {
return issue;
}
}

if (checks !== undefined) {
for (const { func, issue } of checks) {
if (!func(output ?? obj)) {
return issue;
}
}
return output && { ok: true, value: output };
}
return output && { ok: true, value: output };
};
}

Expand Down

0 comments on commit eabf924

Please sign in to comment.