A
arktype4w ago
Dawei

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
TizzySaurus
TizzySaurus4w ago
You can do type("===", ...accessList)
TizzySaurus
TizzySaurus4w ago
And in v2.2 (the next release) there will be a type.union(): https://github.com/arktypeio/arktype/issues/1319
GitHub
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...
Dawei
DaweiOP4w ago
it works, thanks. is this documented ? maybe I missed something in the doc..
TizzySaurus
TizzySaurus4w ago
ArkType Docs
TypeScript's 1:1 validator, optimized from editor to runtime
TizzySaurus
TizzySaurus4w ago
This being the args version There's type.enumerated(arr) if you prefer that over type("===", ...arr)

Did you find this page helpful?