import type {Dependencies, Signature} from '../interfaces/type.js' import {$$typeToString} from 'ts-macros' export const square = (dep: Dependencies<'multiply', T>): Signature<'square', T> => z => dep.multiply(z, z) // z => dep.fooBar(z, z) // fails as desired // z => dep.multiply(z, 'foo') // still fails as desired // make sure ts-macros is running function $contains(value: T, ...possible: Array) { // repetition which goes over all the elements in the "possible" array return +["||", [possible], (item: T) => value === item]; } const searchItem = "needle"; console.log("In generic arithmetic") console.log($contains!(searchItem, "erwin", "tj")); // Transpiles to: console.log(false); // OK, record the type of square: square.reflectedType = $$typeToString!(); 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!<() => Out>()) type OutB = ExpandTwice>; console.log("Or perhaps", $$typeToString!()) console.log("Or maybe even", $$typeToString!< (...args: DeepExpand>>) => DeepExpand>> >())