how to do an union of dynamic literals ?
in valibot I use :
const accessList = ["public", "premium"] as const;
const accessSchema = v.picklist(accessList);
in arktype I have to repeat the values ?
const accessList = ["public", "premium"] as const;
const accessSchema = type("'public' | 'premium'");
5 Replies
You can do
type("===", ...accessList)
And in v2.2 (the next release) there will be a
type.union()
: https://github.com/arktypeio/arktype/issues/1319GitHub
add method helpers for n-ary operators (or, and, merge) · Issue #13...
Request a feature 🤷 Motivation I am trying to compose typed enums into a larger union type for a variable number of types: export function Agent<Resources extends type<any>[]>(resources...
it works, thanks. is this documented ? maybe I missed something in the doc..
ArkType Docs
TypeScript's 1:1 validator, optimized from editor to runtime
This being the
args
version
There's type.enumerated(arr)
if you prefer that over type("===", ...arr)