Skip to content

Conversation

@jiji-hoon96
Copy link
Contributor

Problem

z.record() schema fails to parse plain objects with non-function constructor field, throwing "Invalid input: expected record, received object" error.

Solution

Add type check in isPlainObject function to treat objects with non-function constructor as plain objects.

Tests

  • Added comprehensive test cases for constructor field scenarios
  • All existing 2827 tests pass
  • No regressions

Closes #5066

const ctor = o.constructor;
if (ctor === undefined) return true;

if (typeof ctor !== "function") return true;
Copy link

@adam-coster adam-coster Aug 18, 2025

Choose a reason for hiding this comment

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

Line 380 could replace line 378, instead of having both, since this check includes the case where ctor === undefined (since in that case typeof ctor is "undefined", which does not equal "function"). But the extra clarity doesn't hurt anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're suggestion is technically correct - line 380 (typeof ctor !== "function") would handle both cases since typeof undefined returns "undefined", not "function".
However, I'd keep both lines for clarity. The explicit undefined check makes the intent more obvious and doesn't hurt performance.
It's a style preference, and the current approach is more readable.

@jiji-hoon96
Copy link
Contributor Author

jiji-hoon96 commented Oct 13, 2025

@colinhacks I believe this issue needs to be addressed. I would appreciate it if you could review the PR. 🙏

@flbn
Copy link

flbn commented Oct 21, 2025

any updates on this?

@jiji-hoon96
Copy link
Contributor Author

There are no additional changes, and we are awaiting the maintainer's approval.

@flbn
Copy link

flbn commented Oct 30, 2025

@colinhacks there's some other people with interest, would love to help out and get this merged if this is the desired fix.

@flbn
Copy link

flbn commented Nov 4, 2025

^^^ following up again, working around this isn't great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Invalid input: expected record, received object" for plain object with non-function constructor field

3 participants