diff --git a/types/es6-promisify/es6-promisify-tests.ts b/types/es6-promisify/es6-promisify-tests.ts new file mode 100644 index 0000000000..e2e004a950 --- /dev/null +++ b/types/es6-promisify/es6-promisify-tests.ts @@ -0,0 +1,31 @@ +/// + +import promisify = require('es6-promisify'); + +function callbackFunction(a: string, b: string, callback: (error: any, combined: string) => void): void { + callback(undefined, a + b); +} + +function multiArgFunction(a: string, b: string, c: string, callback: (error: any, ac: string, bc: string) => void): void { + callback(undefined, a + c, b + c); +} + +const noKeys: promisify.Settings = {}; +const multiArgFunctionSettings: promisify.Settings = { + thisArg: multiArgFunction, + multiArgs: true +}; + +const callbackPromiseFactory: (...args: any[]) => Promise = promisify(callbackFunction); +const multiArgPromiseFactory: (...args: any[]) => Promise = promisify(multiArgFunction, multiArgFunctionSettings); + +const callbackPromise: Promise = callbackPromiseFactory('stringA', 'stringB'); +const multiArgPromise: Promise = multiArgPromiseFactory('stringA', 'stringB', 'stringC'); + +callbackPromise.then((concat: string): void => { +}).catch((error: any) => { +}); + +multiArgPromise.then((concat: string[]): void => { +}).catch((error: any) => { +}); diff --git a/types/es6-promisify/index.d.ts b/types/es6-promisify/index.d.ts new file mode 100644 index 0000000000..8965b48503 --- /dev/null +++ b/types/es6-promisify/index.d.ts @@ -0,0 +1,24 @@ +// Type definitions for es6-promisify 5.0 +// Project: https://github.com/digitaldesignlabs/es6-promisify#readme +// Definitions by: Harry Shipton +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare function es6_promisify(original: (...args: any[]) => any, settings?: es6_promisify.Settings): ((...args: any[]) => Promise); + +// If the issue at https://github.com/Microsoft/TypeScript/issues/1360 is fixed, +// then an update should be submitted replacing the above declaration with the +// following declarations. +/* +declare function es6_promisify(original: (...args: any[], callback: (error: any, arg: T) => any) => any, settings?: Settings): ((...args: any[]) => Promise); + +declare function es6_promisify(original: (...args: any[], callback: (error: any, ...args: any[]) => any) => any, settings?: Settings): ((...args: any[]) => Promise); +*/ + +declare namespace es6_promisify { + interface Settings { + thisArg?: any; + multiArgs?: boolean; + } +} + +export = es6_promisify; diff --git a/types/es6-promisify/tsconfig.json b/types/es6-promisify/tsconfig.json new file mode 100644 index 0000000000..d28d909997 --- /dev/null +++ b/types/es6-promisify/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "es6-promisify-tests.ts" + ] +} diff --git a/types/es6-promisify/tslint.json b/types/es6-promisify/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/es6-promisify/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }