-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove enum types #966
Copy link
Copy link
Open
Labels
approvedApproved for a PR, if you assigned to the issue.Approved for a PR, if you assigned to the issue.good first issueGood for new contributors.Good for new contributors.
Milestone
Metadata
Metadata
Assignees
Labels
approvedApproved for a PR, if you assigned to the issue.Approved for a PR, if you assigned to the issue.good first issueGood for new contributors.Good for new contributors.
Type
Fields
Give feedbackNo fields configured for Task.
Projects
StatusShow more project fields
Development
Description
enums with strings unions.becomes:
enums with eslint:Justification
Enums do not behave as you might expect at runtime, because enums are not a native feature of javascript. The typescript compiler creates a strange looking object when you use the
enumkeyword:And when you run this weird code, you get this exceptional result:
Things get a little bit better if you set the enum values to strings, but only if the keys and values match. If they do not match, zod will create types based on the key, but the values will actually be used, resulting in schema validation errors.