Skip to content
Merged
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
5 changes: 5 additions & 0 deletions types/devicefarmer__stf-syrup/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
45 changes: 45 additions & 0 deletions types/devicefarmer__stf-syrup/devicefarmer__stf-syrup-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Syrup from "@devicefarmer/stf-syrup";
import Promise from "bluebird";

const moduleA = Syrup.serial().define((options) => {
if (Math.random()) {
return "a";
} else {
return 0;
}
});

const moduleB = Syrup.serial().define((options) => {
return "b";
});

const moduleC = Syrup.serial()
.dependency(moduleA)
.dependency(moduleB)
.define((options, a, b) => {
// $ExpectType "a" | 0
const resa = a;

// $ExpectType string
const resb = b;
});

// @ts-expect-error
Syrup.serial().define((options, a) => {
});

// @ts-expect-error
Syrup().dependency();

// This will throw a runtime error but should compile
Syrup().consume({});

// $ExpectType Promise<number>
const e = Syrup().define(() => 0).consume({ "a": 3 });

// $ExpectType Promise<number>
const e2 = Syrup().define((options: { a: number }) => options.a).consume({ "a": 3, "unused": 5 });

const e3 = Syrup()
.define((options: { a: number; b: number }) => options.a + options.b)
.consume({ "a": 3, "unused": 5 }); // this is wrong because we are not passing option b, but the way the library is used this should typecheck.
55 changes: 55 additions & 0 deletions types/devicefarmer__stf-syrup/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Bluebird = require("bluebird");

type extractDesRet<RetT> = RetT extends SyrupI<never, never, infer RetX> ? RetX
: unknown;
type extractBluebirdReturnR<RetT> = RetT extends Bluebird<infer RetX> ? RetX
: RetT;
declare 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,
DepsRetsT extends unknown[] = [], // 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<OptionsT>(
overrides: OptionsT,
): Bluebird<RetT>;
invoke(overrides: OptionsT, ...args: DepsT[]): RetT;
}

declare function ParallelSyrup(
options?: object,
): SyrupI;
declare namespace ParallelSyrup {
const Syrup: SyrupI;
}

declare function SerialSyrup(
options?: object,
): SyrupI;
declare namespace SerialSyrup {
const Syrup: SyrupI;
}

declare const Syrup: typeof ParallelSyrup & {
serial: typeof SerialSyrup;
};
export = Syrup;
20 changes: 20 additions & 0 deletions types/devicefarmer__stf-syrup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"private": true,
"name": "@types/devicefarmer__stf-syrup",
"version": "1.0.9999",
"projects": [
"https://github.com/DeviceFarmer/stf-syrup/"
],
"dependencies": {
"@types/bluebird": "^1.0.8"
},
"devDependencies": {
"@types/devicefarmer__stf-syrup": "workspace:."
},
"owners": [
{
"name": "Maksim Alzhanov",
"githubUsername": "irdkwmnsb"
}
]
}
19 changes: 19 additions & 0 deletions types/devicefarmer__stf-syrup/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "node16",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"devicefarmer__stf-syrup-tests.ts"
]
}
2 changes: 1 addition & 1 deletion types/vscode/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*--------------------------------------------------------------------------------------------*/

/**
* Type Definition for Visual Studio Code 1.98 Extension API
* Type Definition for Visual Studio Code 1.99 Extension API
* See https://code.visualstudio.com/api for more information
*/

Expand Down