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

Enum type returns string #70

Closed
jdgamble555 opened this issue Aug 6, 2023 · 4 comments
Closed

Enum type returns string #70

jdgamble555 opened this issue Aug 6, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request priority This has priority

Comments

@jdgamble555
Copy link

jdgamble555 commented Aug 6, 2023

I have a schema like this:

const postSchema = object({
    status: optional(enumType(['publish', "future", "draft", "pending", "private", "trash", "auto-draft", "inherit"]))
});

However, this returns a string type. While it does validate this correctly, the typing is not the correct type.

This is not the expected result as 'string' and 'enum' are completely different. If I pass the result.data.status to an enum type, I get an error because it is a string type, while technically validated.

J

@fabian-hiller
Copy link
Owner

Does it work with as const?

const postSchema = object({
  status: optional(
    enumType([
      'publish',
      'future',
      'draft',
      'pending',
      'private',
      'trash',
      'auto-draft',
      'inherit',
    ] as const)
  ),
});

@fabian-hiller fabian-hiller self-assigned this Aug 6, 2023
@fabian-hiller fabian-hiller added the question Further information is requested label Aug 6, 2023
@jdgamble555
Copy link
Author

Yes, that seems to fix the problem. Shouldn't this be done automatically under the hood?

J

@fabian-hiller
Copy link
Owner

If it is possible, then yes. Maybe I can do the conversion to readonly in the library code. I will check this.

@fabian-hiller fabian-hiller added enhancement New feature or request priority This has priority and removed question Further information is requested labels Aug 6, 2023
@fabian-hiller
Copy link
Owner

I was able to solve the problem. With the next update the changes will go live.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority This has priority
Projects
None yet
Development

No branches or pull requests

2 participants