Merge pull request #19048 from harryshipton/es6-promisify

[es6-promisify] Add typings
This commit is contained in:
Daniel Rosenwasser
2017-08-18 15:25:04 -07:00
committed by GitHub
4 changed files with 78 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
/// <reference types="node" />
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<string> = promisify(callbackFunction);
const multiArgPromiseFactory: (...args: any[]) => Promise<string[]> = promisify(multiArgFunction, multiArgFunctionSettings);
const callbackPromise: Promise<string> = callbackPromiseFactory('stringA', 'stringB');
const multiArgPromise: Promise<string[]> = multiArgPromiseFactory('stringA', 'stringB', 'stringC');
callbackPromise.then((concat: string): void => {
}).catch((error: any) => {
});
multiArgPromise.then((concat: string[]): void => {
}).catch((error: any) => {
});

24
types/es6-promisify/index.d.ts vendored Normal file
View File

@@ -0,0 +1,24 @@
// Type definitions for es6-promisify 5.0
// Project: https://github.com/digitaldesignlabs/es6-promisify#readme
// Definitions by: Harry Shipton <https://github.com/harryshipton>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function es6_promisify(original: (...args: any[]) => any, settings?: es6_promisify.Settings): ((...args: any[]) => Promise<any>);
// 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<T>(original: (...args: any[], callback: (error: any, arg: T) => any) => any, settings?: Settings): ((...args: any[]) => Promise<T>);
declare function es6_promisify(original: (...args: any[], callback: (error: any, ...args: any[]) => any) => any, settings?: Settings): ((...args: any[]) => Promise<any[]>);
*/
declare namespace es6_promisify {
interface Settings {
thisArg?: any;
multiArgs?: boolean;
}
}
export = es6_promisify;

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }