feat: Simplify the reflected type of an implementation
This commit is contained in:
parent
da5b2c3467
commit
af02f1cb29
@ -21,7 +21,21 @@ console.log($contains!(searchItem, "erwin", "tj"));
|
||||
// OK, record the type of square:
|
||||
square.reflectedType = $$typeToString!<typeof square>();
|
||||
|
||||
type Expand<T> = T extends unknown ? { [K in keyof T]: T[K] } : never;
|
||||
type Out = Expand<Dependencies<'multiply', number>>;
|
||||
type ShallowExpand<T> = T extends unknown ? { [K in keyof T]: T[K] } : never;
|
||||
type ExpandedParameters<T extends (...args: any) => any> = {[Index in keyof Parameters<T>]: ShallowExpand<Parameters<T>[Index]>}
|
||||
type ExpandTwice<T extends any[]> = {[Index in keyof T] : ShallowExpand<T[Index]>}
|
||||
type AsArray<T> = T extends any[] ? T : [];
|
||||
type DeepExpand<T> =
|
||||
T extends (...args: any) => any ? (...pars: AsArray<DeepExpand<Parameters<T>>>) => DeepExpand<ReturnType<T>> :
|
||||
T extends unknown ? { [K in keyof T]: DeepExpand<T[K]> } : never;
|
||||
type Out<T> = ShallowExpand<Dependencies<'multiply', T>>;
|
||||
|
||||
console.log("Deps type is", $$typeToString!<Out>())
|
||||
console.log("Deps type is", $$typeToString!<<T>() => Out<T>>())
|
||||
|
||||
type OutB = ExpandTwice<Parameters<typeof square>>;
|
||||
|
||||
console.log("Or perhaps", $$typeToString!<OutB>())
|
||||
|
||||
console.log("Or maybe even", $$typeToString!<
|
||||
<T>(...args: DeepExpand<Parameters<typeof square<T>>>) => DeepExpand<ReturnType<typeof square<T>>>
|
||||
>())
|
||||
|
Loading…
Reference in New Issue
Block a user