typia
Version:
Superfast runtime validators with only one line
7 lines (6 loc) • 440 B
TypeScript
export type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true ? boolean : IsValueOf<Instance, Number> extends true ? number : IsValueOf<Instance, String> extends true ? string : Instance;
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object ? Object extends IValueOf<infer Primitive> ? Instance extends Primitive ? false : true : false : false;
interface IValueOf<T> {
valueOf(): T;
}
export {};