arktypea
arktype10mo ago
Ben

Easy way to validate enums

Brand new to Arktype(migrating over from Zod for perf reasons), and have a question about about handling enums. We have a fair number of enums that we use in our validation, example with Zod might be something like:

  period: z.nativeEnum(Period),


Seems like a way to do this in ArkType might be something like:

period: `"${Object.values(Period).join('"|"')}"`,


I tried to create a helper function so I don't have to do Object.values thing everywhere:

export const enumToArktype = (enumObj: Record<string, string>) => {
  return `"${Object.values(enumObj).join('"|"')}"`;
};


But Arktype doesn't seem to like the return type on this. Any ideas as to how to easily handle this use case?
Was this page helpful?