pivots
Version:
## Readable [discriminated unions](https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions) for TypeScript
16 lines (15 loc) • 637 B
TypeScript
export declare type Pivots<K extends string, R> = {
[P in keyof R]: {
[L in K]: P;
} & R[P];
}[keyof R];
declare type PivotsCase<B extends string, T, U = {}> = {
[P in B]: T;
} & U;
export declare type PivotsOnly<K extends string, Union extends PivotsCase<K, any>, Cases extends Union[K]> = Extract<Union, {
[L in K]: Cases;
}>;
export declare type PivotsType<R> = Pivots<'type', R>;
declare type PivotsTypeCase<T, U = {}> = PivotsCase<'type', T, U>;
export declare type PivotsOnlyTypes<Union extends PivotsTypeCase<any>, Types extends Union['type']> = PivotsOnly<'type', Union, Types>;
export {};