From af02f1cb29e85bb6eae53c63f59f691b8b4ce09b Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Fri, 18 Aug 2023 20:29:24 -0700 Subject: [PATCH] feat: Simplify the reflected type of an implementation --- src/generic/arithmetic.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/generic/arithmetic.ts b/src/generic/arithmetic.ts index 57bacad..5e6fc7e 100644 --- a/src/generic/arithmetic.ts +++ b/src/generic/arithmetic.ts @@ -21,7 +21,21 @@ console.log($contains!(searchItem, "erwin", "tj")); // OK, record the type of square: square.reflectedType = $$typeToString!(); -type Expand = T extends unknown ? { [K in keyof T]: T[K] } : never; -type Out = Expand>; +type ShallowExpand = T extends unknown ? { [K in keyof T]: T[K] } : never; +type ExpandedParameters any> = {[Index in keyof Parameters]: ShallowExpand[Index]>} +type ExpandTwice = {[Index in keyof T] : ShallowExpand} +type AsArray = T extends any[] ? T : []; +type DeepExpand = + T extends (...args: any) => any ? (...pars: AsArray>>) => DeepExpand> : + T extends unknown ? { [K in keyof T]: DeepExpand } : never; +type Out = ShallowExpand>; -console.log("Deps type is", $$typeToString!()) +console.log("Deps type is", $$typeToString!<() => Out>()) + +type OutB = ExpandTwice>; + +console.log("Or perhaps", $$typeToString!()) + +console.log("Or maybe even", $$typeToString!< + (...args: DeepExpand>>) => DeepExpand>> + >())