type EnumItem = string | {label: string; value: string;};
export type FormItem = {
label?: string;
type: 'string';
default: string | null;
hidden?: boolean;
multiline?: boolean;
} | {
type: 'number';
default: number | null;
step?: number;
type: 'boolean';
default: boolean | null;
type: 'enum';
enum: EnumItem[];
type: 'radio';
default: unknown | null;
options: {
label: string;
value: unknown;
}[];
type: 'object';
default: Record<string, unknown> | null;
hidden: true;
type: 'array';
default: unknown[] | null;
};
export type Form = Record<string, FormItem>;
type GetItemType<Item extends FormItem> =
Item['type'] extends 'string' ? string :
Item['type'] extends 'number' ? number :
Item['type'] extends 'boolean' ? boolean :
Item['type'] extends 'radio' ? unknown :
Item['type'] extends 'enum' ? string :
Item['type'] extends 'array' ? unknown[] :
Item['type'] extends 'object' ? Record<string, unknown>
: never;
export type GetFormResultType<F extends Form> = {
[P in keyof F]: GetItemType<F[P]>;