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

const values #240

Open
mfulton26 opened this issue Jun 24, 2022 · 1 comment
Open

const values #240

mfulton26 opened this issue Jun 24, 2022 · 1 comment

Comments

@mfulton26
Copy link

I want to be able to validate that a value is one of several specific values and then get a union type returned

e.g.

ow.string.oneOf(["on", "off"] as const)

The type would be StringPredicate<"on" | "off"> rather than simply StringPredicate or some subclass of Predicate<T>.

A different solution that might work would be to use ow.any(…) so that union types can be defined for more than just strings:

ow.any(ow.const("on" as const), ow.const("off" as const))
@sindresorhus
Copy link
Owner

I think both would be useful, but I haven't looked into whether it's possible.

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

No branches or pull requests

2 participants