10 lines
318 B
TypeScript
10 lines
318 B
TypeScript
import { z } from "zod";
|
|
|
|
export function zodEnumFromObjectKeys<
|
|
TI extends Record<string, any>,
|
|
R extends string = TI extends Record<infer R, any> ? R : never
|
|
>(input: TI): z.ZodEnum<[R, ...R[]]> {
|
|
const [firstKey, ...otherKeys] = Object.keys(input) as [R, ...R[]];
|
|
return z.enum([firstKey, ...otherKeys]);
|
|
}
|