8000 Object.freeze(["a","b"]) is not a valid z.enum parameter · Issue #4307 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Object.freeze(["a","b"]) is not a valid z.enum parameter #4307

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

Closed
AlvesJorge opened this issue May 2, 2025 · 1 comment
Closed

Object.freeze(["a","b"]) is not a valid z.enum parameter #4307

AlvesJorge opened this issue May 2, 2025 · 1 comment

Comments

@AlvesJorge
Copy link
AlvesJorge commented May 2, 2025

zod version: 3.24.3
Sandbox reproduction: https://codesandbox.io/p/sandbox/866jqq

as const works but freezing the object fails with No overload matches this call.
Is this expected behavior? If so why?

@colinhacks
Copy link
Owner

Object.freeze() does not indicate to TypeScript that it should treat the value as a const. It returns readonly string[] which means z.enum() isn't able to infer the individual enum elements. Try Object.freeze(["a","b"] as const) if you want to freeze, but you'll definitely need as const.

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

No branches or pull requests

2 participants
0