mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-24 13:59:25 +08:00
Merge pull request #19048 from harryshipton/es6-promisify
[es6-promisify] Add typings
This commit is contained in:
31
types/es6-promisify/es6-promisify-tests.ts
Normal file
31
types/es6-promisify/es6-promisify-tests.ts
Normal 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
24
types/es6-promisify/index.d.ts
vendored
Normal 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;
|
||||
22
types/es6-promisify/tsconfig.json
Normal file
22
types/es6-promisify/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/es6-promisify/tslint.json
Normal file
1
types/es6-promisify/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user