rivo
Version:
🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
37 lines (32 loc) • 1.1 kB
TypeScript
import type { None, Option, OptionL, Some } from ".";
import type { Args, Fn } from "../HKT";
import type { Show, TypeClass$$Show } from "../typeclass";
import type { Show as Show_ } from "../typeclass/Show/Show";
declare module "../typeclass/Show" {
interface ShowImpl {
Option: ImplShowFor<OptionL<ShowL>, Option$$Show>;
}
}
/**
* Implementation of the {@link Show} type class for {@link Option}.
*/
export interface Option$$Show extends TypeClass$$Show<Option<Show>> {
Show: Option$$Show$ShowFn;
}
/**
* [Fn] Show an {@link Option}.
*/
interface Option$$Show$ShowFn extends Fn<[Option<Show>], string> {
// @ts-ignore - Return type annotation circularly references itself.
def: ([xs]: Args<this>) => Option$$Show$Show<typeof xs>;
}
/**
* Show an {@link Option}.
*/
type Option$$Show$Show<O extends Option<Show>> =
[O] extends [Some<infer T extends Show>] ?
// @ts-ignore - Type instantiation is excessively deep and possibly infinite.
`Some<${Show_<T>}>`
: [O] extends [None] ? "None"
: [O] extends [Option<infer T extends Show>] ? `Option<${Show_<T>}>`
: never;