diff --git a/types/devicefarmer__stf-syrup/.npmignore b/types/devicefarmer__stf-syrup/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/devicefarmer__stf-syrup/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/devicefarmer__stf-syrup/devicefarmer__stf-syrup-tests.ts b/types/devicefarmer__stf-syrup/devicefarmer__stf-syrup-tests.ts new file mode 100644 index 00000000000000..254db3d26a00e0 --- /dev/null +++ b/types/devicefarmer__stf-syrup/devicefarmer__stf-syrup-tests.ts @@ -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 +const e = Syrup().define(() => 0).consume({ "a": 3 }); + +// $ExpectType Promise +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. diff --git a/types/devicefarmer__stf-syrup/index.d.ts b/types/devicefarmer__stf-syrup/index.d.ts new file mode 100644 index 00000000000000..73a0e95092b6e8 --- /dev/null +++ b/types/devicefarmer__stf-syrup/index.d.ts @@ -0,0 +1,55 @@ +import Bluebird = require("bluebird"); + +type extractDesRet = RetT extends SyrupI ? RetX + : unknown; +type extractBluebirdReturnR = RetT extends Bluebird ? 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>, + DepsRetsT + >; + dependency>( + dep: DepT, + ): SyrupI< + OptionsT, + [...DepsT, DepT], + RetT, + [...DepsRetsT, extractDesRet] + >; + consume( + overrides: OptionsT, + ): Bluebird; + 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; diff --git a/types/devicefarmer__stf-syrup/package.json b/types/devicefarmer__stf-syrup/package.json new file mode 100644 index 00000000000000..ab6c59f96e0349 --- /dev/null +++ b/types/devicefarmer__stf-syrup/package.json @@ -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" + } + ] +} diff --git a/types/devicefarmer__stf-syrup/tsconfig.json b/types/devicefarmer__stf-syrup/tsconfig.json new file mode 100644 index 00000000000000..a010c200031f4c --- /dev/null +++ b/types/devicefarmer__stf-syrup/tsconfig.json @@ -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" + ] +} diff --git a/types/vscode/index.d.ts b/types/vscode/index.d.ts index 1d85346d414561..e7b4f490edb970 100644 --- a/types/vscode/index.d.ts +++ b/types/vscode/index.d.ts @@ -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 */