rivo
Version:
🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
38 lines (34 loc) • 1.16 kB
TypeScript
import type { Show, Show$GetConstruct, Show$GetTypeClass } from ".";
import type { Args, Call1W, Fn } from "../../HKT";
import type { IsUnion } from "../../Union/IsUnion";
import type { ToList } from "../../Union/ToList";
import type { And, AssertStr, IsAny, Not, Or } from "../../helpers";
type _ShowUnion<TS> =
TS extends [infer S extends Show] ? Show_<S>
: TS extends [infer H extends Show, ...infer R] ?
// @ts-ignore - Type instantiation is excessively deep and possibly infinite.
`${Show_<H>} | ${_ShowUnion<R>}`
: never;
/**
* Convert a `Show` instance to a string.
*
* Sig: `(s: Show) => string`
*/
type Show_<S extends Show> = AssertStr<
IsAny<S> extends true ? string
: And<IsUnion<S>, Or<IsUnion<Show$GetTypeClass<S>>, Not<IsUnion<Show$GetConstruct<S>>>>> extends (
true
) ?
_ShowUnion<ToList<S>>
: Call1W<Show$GetTypeClass<S>["Show"], S> extends infer U extends string ? U
: never
>;
export type { Show_ as Show };
/**
* [Fn] Convert a `Show` instance to a string.
*
* Sig: `(s: Show) => string`
*/
export default interface ShowFn extends Fn<[Show], string> {
def: ([s]: Args<this>) => Show_<typeof s>;
}