Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add syrup types for ide highlighting #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions lib/types/syrup.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
declare module "@devicefarmer/stf-syrup" {
import Bluebird from "bluebird";
type extractDesRet<RetT> = RetT extends SyrupI<never, never, infer RetX>
? RetX
: unknown;
type extractBluebirdReturnR<RetT> = RetT extends Bluebird<infer RetX>
? 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<ReturnType<typeof body>>,
DepsRetsT
>;
dependency<DepT extends SyrupI<never, never>>(
dep: DepT
): SyrupI<
OptionsT,
[...DepsT, DepT],
RetT,
[...DepsRetsT, extractDesRet<DepT>]
>;
consume<NewOptionsT extends OptionsT>(
overrides: NewOptionsT
): Bluebird<RetT>;
invoke(overrides: OptionsT, ...args: DepsT[]): RetT;
}
type ParallelSyrup = <OptionsT extends object>(
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;
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"moduleResolution": "node",
"outDir": "dist"
},
"include": ["./lib/**/*.js"],
"include": ["./lib/**/*.js", "./lib/types/**/*.d.ts", "./lib/**/*.ts"],
"verbose": true
}