@kakasoo/proto-typescript
Version:
Utility types and implementations based on JavaScript prototypes.
43 lines • 2.02 kB
TypeScript
import { ToPrimitive } from '../interfaces';
import { Equal, ReadonlyOrNot } from '../types';
import { TypedObject } from './typed-object.class';
export declare class TypedBoolean<T extends boolean = false> extends TypedObject<T> implements ToPrimitive<T> {
private readonly boolean;
constructor(data?: T);
/**
* @example
* ```ts
* const yn = TypedBoolean.refine({ true: 'Y', false: 'N' });
*
* const t = yn('Y'); // true
* const f = yn('N'); // false
* const y = yn(true); // 'Y'
* const n = yn(false); // 'N'
* ```
* @param map Defines the key name that you want to specify with true and false.
* @returns
*/
refine<T extends string, F extends string>(map: {
true: T;
false: F;
}): <Choice extends boolean | T | F>(data: boolean | Choice) => Equal<Choice, T> extends true ? true : Equal<Choice, F> extends true ? false : Equal<Choice, true> extends true ? T : Equal<Choice, false> extends true ? F : never;
static refine<T extends string, F extends string>(map: {
true: T;
false: F;
}): <Choice extends boolean | T | F>(data: boolean | Choice) => Equal<Choice, T> extends true ? true : Equal<Choice, F> extends true ? false : Equal<Choice, true> extends true ? T : Equal<Choice, false> extends true ? F : never;
toPrimitive(): T;
}
export declare namespace TypedBoolean {
/**
* Inference of value type.
*/
type ValueType<Pointer extends TypedBoolean<any> | Boolean> = Pointer extends TypedBoolean<infer T> ? `${T}` : Pointer extends boolean ? Pointer : never;
/**
* Inference of value types.
*/
type ValueTypes<Pointers extends ReadonlyOrNot<(TypedBoolean<any> | boolean)[]>> = Pointers extends [
infer F extends TypedBoolean<infer T> | boolean,
...infer Rest extends ReadonlyOrNot<(TypedBoolean<any> | boolean)[]>
] ? [TypedBoolean.ValueType<F>, ...TypedBoolean.ValueTypes<Rest>] : [];
}
//# sourceMappingURL=typed-boolean.class.d.ts.map