ow icon indicating copy to clipboard operation
ow copied to clipboard

const values

Open mfulton26 opened this issue 2 years ago • 1 comments

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))

mfulton26 avatar Jun 24 '22 21:06 mfulton26

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

sindresorhus avatar Jun 26 '22 10:06 sindresorhus