diff --git a/lib/types/syrup.d.ts b/lib/types/syrup.d.ts new file mode 100644 index 000000000..bef67aac4 --- /dev/null +++ b/lib/types/syrup.d.ts @@ -0,0 +1,57 @@ +declare module "@devicefarmer/stf-syrup" { + import Bluebird from "bluebird"; + type extractDesRet = RetT extends SyrupI + ? RetX + : unknown; + type extractBluebirdReturnR = RetT extends Bluebird + ? RetX + : RetT; + class SyrupI< + OptionsT extends object = any, // TODO: find a way to remove any. Maybe we union all the options that are needed for each dependency? + DepsT extends SyrupI[] = [], + RetT = unknown | void, + DepsRetsT extends (unknown | void)[] = [] // TODO: maybe we can extract DepsRetsT somehow? + > { + constructor(options: OptionsT | null); + define< + BodyT extends (options: OptionsT, ...deps: DepsRetsT) => unknown + >( + body: BodyT + ): SyrupI< + OptionsT, + DepsT, + extractBluebirdReturnR>, + DepsRetsT + >; + dependency>( + dep: DepT + ): SyrupI< + OptionsT, + [...DepsT, DepT], + RetT, + [...DepsRetsT, extractDesRet] + >; + consume( + overrides: NewOptionsT + ): Bluebird; + invoke(overrides: OptionsT, ...args: DepsT[]): RetT; + } + type ParallelSyrup = ( + options?: OptionsT + ) => SyrupI; + namespace ParallelSyrup { + const Syrup: SyrupI; + } + + type SerialSyrup = ParallelSyrup; + namespace SerialSyrup { + const Syrup: SyrupI; + } + + type Syrup = ParallelSyrup; + namespace Syrup { + const serial: SerialSyrup; + } + + export = Syrup; +} diff --git a/tsconfig.json b/tsconfig.json index 11153f944..c2198977f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,6 @@ "moduleResolution": "node", "outDir": "dist" }, - "include": ["./lib/**/*.js"], + "include": ["./lib/**/*.js", "./lib/types/**/*.d.ts", "./lib/**/*.ts"], "verbose": true }