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.

36 lines
885 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]>;
};
export type Unconst<T> = [T] extends [Const<infer U>] ? U : never;
export type ReturnTypes<T extends ((...args: any) => any)[]> = {
[K in keyof T]: ReturnType<T[K]>;
}[number];
type A = ReturnTypes<[() => number, () => string]>;
export type UnionToIntersection<U> = (
U extends any ? (k: U) => void : never
) extends (k: infer I) => void
? I
: never;