Merge pull request #3839 from jasonswearingen/master

add typing for bluebird Promise.promisify, and new typing for hapi v8.2.0
This commit is contained in:
Masahiro Wakame
2015-03-15 22:33:31 +09:00
3 changed files with 2179 additions and 418 deletions
+6 -1
View File
@@ -404,7 +404,12 @@ declare class Promise<R> implements Promise.Thenable<R>, Promise.Inspection<R> {
*
* If you pass a `receiver`, the `nodeFunction` will be called as a method on the `receiver`.
*/
// TODO how to model promisify?
static promisify<T>(func: (callback: (err:any, result: T) => void) => void, receiver?: any): () => Promise<T>;
static promisify<T, A1>(func: (arg1: A1, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1) => Promise<T>;
static promisify<T, A1, A2>(func: (arg1: A1, arg2: A2, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2) => Promise<T>;
static promisify<T, A1, A2, A3>(func: (arg1: A1, arg2: A2, arg3: A3, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2, arg3: A3) => Promise<T>;
static promisify<T, A1, A2, A3, A4>(func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Promise<T>;
static promisify<T, A1, A2, A3, A4, A5>(func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5, callback: (err: any, result: T) => void) => void, receiver?: any): (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Promise<T>;
static promisify(nodeFunction: Function, receiver?: any): Function;
/**
+19 -15
View File
@@ -1,9 +1,13 @@
/// <reference path="hapi.d.ts" />
import Hapi = require('hapi');
import Hapi = require("hapi");
// Create a server with a host and port
var server = Hapi.createServer('localhost', 8000);
var server = new Hapi.Server();
server.connection({
host: "localhost",
port: 8000,
});
// Add plugins
var plugin: any = {
@@ -13,26 +17,26 @@ var plugin: any = {
};
plugin.register.attributes = {
name: 'test',
version: '1.0.0'
name: "test",
version: "1.0.0"
};
server.pack.register(plugin, (err: Object) => {
if (err) { throw err; }
});
//server.pack.register(plugin, (err: Object) => {
// if (err) { throw err; }
//});
server.pack.register([plugin], (err: Object) => {
if (err) { throw err; }
});
//server.pack.register([plugin], (err: Object) => {
// if (err) { throw err; }
//});
// Add server method
var add = function (a: number, b: number, next: (err: any, result?: any, ttl?: number) => void) {
next(null, a + b);
};
server.method('sum', add, { cache: { expiresIn: 2000 } });
server.method("sum", add);//, { cache: { expiresIn: 2000 } });
server.methods.sum(4, 5, (err: any, result: any) => {
server.methods["sum"](4, 5, (err: any, result: any) => {
console.log(result);
});
@@ -44,14 +48,14 @@ var addArray = function (array: Array<number>, next: (err: any, result?: any, tt
next(null, sum);
};
server.method('sumObj', addArray, {
cache: { expiresIn: 2000 },
server.method("sumObj", addArray, {
//cache: { expiresIn: 2000 },
generateKey: (array: Array<number>) => {
return array.join(',');
}
});
server.methods.sumObj([5, 6], (err: any, result: any) => {
server.methods["sumObj"]([5, 6], (err: any, result: any) => {
console.log(result);
});
+2154 -402
View File
File diff suppressed because it is too large Load Diff