You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
528 B
TypeScript
24 lines
528 B
TypeScript
import { z } from "./deps/zod.ts";
|
|
|
|
export type ZMapLiteral<T extends readonly string[]> = {
|
|
[K in keyof T]: z.ZodLiteral<T[K]>;
|
|
};
|
|
|
|
export const zMapLiteral = <T extends readonly string[]>(
|
|
items: T,
|
|
): ZMapLiteral<T> => {
|
|
return items.map((i) => z.literal(i)) as ZMapLiteral<T>;
|
|
};
|
|
|
|
export const zUnionLiterals = <
|
|
T extends readonly [string, string, ...string[]],
|
|
>(
|
|
items: T,
|
|
): z.ZodUnion<ZMapLiteral<T>> => {
|
|
return z.union(zMapLiteral(items));
|
|
};
|
|
|
|
export type Const<T> = {
|
|
readonly [K in keyof T]: Const<T[K]>;
|
|
};
|