/** Flattens an intersection into one object type. */ export type Minify = T extends (...args: never[]) => unknown ? T : { [K in keyof T]: T[K] } & {}; /** Alias of {@link Minify}, kept for readability in generated output. */ export type Simplify = Minify; /** Makes every property of `T` readonly, recursively. */ export type DeepReadonly = T extends (...args: never[]) => unknown ? T : T extends readonly (infer U)[] ? readonly DeepReadonly[] : T extends object ? { readonly [K in keyof T]: DeepReadonly } : T; /** Removes `null` and `undefined` from a union. */ export type Defined = Exclude; /** Marks the selected keys of `T` as optional. */ export type WithOptional = Omit & Partial>; /** Marks the selected keys of `T` as required. */ export type WithRequired = Omit & Required>; export function compactTypeSource(source: string): string { const arrow = source.replace(/=>/g, "__ARROW__"); return arrow .replace(/\s+/g, " ") .replace(/\s*([|&=<>?:,()[\]{}])\s*/g, "$1") .replace(/;\s*$/, "") .trim() .replace(/__ARROW__/g, "=>"); } export function indent(source: string, depth = 1): string { const pad = " ".repeat(depth); return source .split("\n") .map((line) => (line.length > 0 ? pad + line : line)) .join("\n"); }