mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-10 11:40:16 +08:00
Added basic typings on q. TypeScript compiler bugs and spec limitations hinder full typing.
This commit is contained in:
+4
-4
@@ -1,6 +1,6 @@
|
||||
/// <reference path="Q.d.ts" />
|
||||
|
||||
Q(8).then(x => console.log(x));
|
||||
Q(8).then(x => console.log(x.toExponential()));
|
||||
|
||||
var delay = function (delay) {
|
||||
var d = Q.defer();
|
||||
@@ -24,11 +24,11 @@ Q.when(x, function (x) {
|
||||
Q.all([
|
||||
eventually(10),
|
||||
eventually(20)
|
||||
])
|
||||
.spread(function (x, y) {
|
||||
]).spread(function (x, y) {
|
||||
console.log(x, y);
|
||||
});
|
||||
|
||||
|
||||
Q.fcall(function () { })
|
||||
.then(function () { })
|
||||
.then(function () { })
|
||||
@@ -40,7 +40,7 @@ Q.fcall(function () { })
|
||||
}).done();
|
||||
|
||||
Q.allResolved([])
|
||||
.then(function (promises: Q.Promise[]) {
|
||||
.then(function (promises: Q.Promise<any>[]) {
|
||||
promises.forEach(function (promise) {
|
||||
if (promise.isFulfilled()) {
|
||||
var value = promise.valueOf();
|
||||
|
||||
@@ -3,66 +3,67 @@
|
||||
// Definitions by: Barrie Nemetchek, Andrew Gaspar
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare function Q(value: any): Q.Promise;
|
||||
declare function Q<T>(value: T): Q.Promise<T>;
|
||||
//declare function Q<T>(value: Q.Promise<T>): Q.Promise<T>
|
||||
declare module Q {
|
||||
interface Deferred {
|
||||
promise: Promise;
|
||||
interface Deferred<T> {
|
||||
promise: Promise<T>;
|
||||
resolve(value: any): any;
|
||||
reject(reason: any);
|
||||
notify(value: any);
|
||||
makeNodeResolver(): () => void;
|
||||
}
|
||||
|
||||
interface Promise {
|
||||
fail(errorCallback: Function): Promise;
|
||||
fin(finallyCallback: Function): Promise;
|
||||
then(onFulfilled?: Function, onRejected?: Function, onProgress?: Function): Promise;
|
||||
spread(onFulfilled: Function, onRejected?: Function): Promise;
|
||||
catch(onRejected: Function): Promise;
|
||||
progress(onProgress: Function): Promise;
|
||||
done(onFulfilled?: Function, onRejected?: Function, onProgress?: Function): Promise;
|
||||
get(propertyName: String): Promise;
|
||||
set(propertyName: String, value: any): Promise;
|
||||
delete(propertyName: String): Promise;
|
||||
post(methodName: String, args: any[]): Promise;
|
||||
invoke(methodName: String, ...args: any[]): Promise;
|
||||
keys(): Promise;
|
||||
fapply(args: any[]): Promise;
|
||||
fcall(method: Function, ...args: any[]): Promise;
|
||||
timeout(ms: number): Promise;
|
||||
delay(ms: number): Promise;
|
||||
interface Promise<T> {
|
||||
fail(errorCallback: Function): Promise<any>;
|
||||
fin(finallyCallback: Function): Promise<any>;
|
||||
then(onFulfilled?: (value: T) => any, onRejected?: (reason) => any, onProgress?: Function): Promise<any>;
|
||||
spread(onFulfilled: Function, onRejected?: Function): Promise<any>;
|
||||
catch(onRejected: Function): Promise<any>;
|
||||
progress(onProgress: Function): Promise<any>;
|
||||
done(onFulfilled?: Function, onRejected?: Function, onProgress?: Function): Promise<any>;
|
||||
get(propertyName: String): Promise<any>;
|
||||
set(propertyName: String, value: any): Promise<any>;
|
||||
delete(propertyName: String): Promise<any>;
|
||||
post(methodName: String, args: any[]): Promise<any>;
|
||||
invoke(methodName: String, ...args: any[]): Promise<any>;
|
||||
keys(): Promise<any>;
|
||||
fapply(args: any[]): Promise<any>;
|
||||
fcall(method: Function, ...args: any[]): Promise<any>;
|
||||
timeout(ms: number): Promise<any>;
|
||||
delay(ms: number): Promise<any>;
|
||||
isFulfilled(): bool;
|
||||
isRejected(): bool;
|
||||
isPending(): bool;
|
||||
valueOf(): any;
|
||||
}
|
||||
|
||||
export function when(value: any, onFulfilled: Function, onRejected?: Function): Promise;
|
||||
//export function try(method: Function, ...args: any[]): Qpromise; <- This is broken currently - not sure how to fix.
|
||||
export function fbind(method: Function, ...args: any[]): Promise;
|
||||
export function fcall(method: Function, ...args: any[]): Promise;
|
||||
export function nfbind(nodeFunction: Function): (...args: any[]) => Promise;
|
||||
export function nfcall(nodeFunction: Function, ...args: any[]): Promise;
|
||||
export function ninvoke(nodeModule: any, functionName: string, ...args: any[]): Promise;
|
||||
export function all(promises: Promise[]): Promise;
|
||||
export function allResolved(promises: Promise[]): Promise;
|
||||
export function spread(onFulfilled: Function, onRejected: Function): Promise;
|
||||
export function timeout(ms: number): Promise;
|
||||
export function delay(ms: number): Promise;
|
||||
export function delay(value: any, ms: number): Promise;
|
||||
export function when(value: any, onFulfilled: Function, onRejected?: Function): Promise<any>;
|
||||
//export function try(method: Function, ...args: any[]): Promise<any>; // <- This is broken currently - not sure how to fix.
|
||||
export function fbind(method: Function, ...args: any[]): Promise<any>;
|
||||
export function fcall(method: Function, ...args: any[]): Promise<any>;
|
||||
export function nfbind(nodeFunction: Function): (...args: any[]) => Promise<any>;
|
||||
export function nfcall(nodeFunction: Function, ...args: any[]): Promise<any>;
|
||||
export function ninvoke(nodeModule: any, functionName: string, ...args: any[]): Promise<any>;
|
||||
export function all(promises: Promise<any>[]): Promise<any>;
|
||||
export function allResolved(promises: Promise<any>[]): Promise<any>;
|
||||
export function spread(onFulfilled: Function, onRejected: Function): Promise<any>;
|
||||
export function timeout(ms: number): Promise<any>;
|
||||
export function delay(ms: number): Promise<any>;
|
||||
export function delay(value: any, ms: number): Promise<any>;
|
||||
export function isFulfilled(): bool;
|
||||
export function isRejected(): bool;
|
||||
export function isPending(): bool;
|
||||
export function valueOf(): any;
|
||||
export function defer(): Deferred;
|
||||
export function reject(): Promise;
|
||||
export function promise(factory: { resolve: Function; reject: Function; notify: Function; }): Promise;
|
||||
export function reject(): Promise<any>;
|
||||
export function promise(factory: { resolve: Function; reject: Function; notify: Function; }): Promise<any>;
|
||||
export function isPromise(value: any): bool;
|
||||
export function async(generatorFunction: any): Deferred;
|
||||
export function nextTick(callback: Function);
|
||||
export var oneerror: any;
|
||||
export var longStackJumpLimit: number;
|
||||
export function resolve(object?: Promise);
|
||||
export function resolve(object?: Promise<any>);
|
||||
}
|
||||
|
||||
declare module "q" {
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
import q = module("q");
|
||||
import fs = module("fs");
|
||||
|
||||
q(8).then(x => console.log(x));
|
||||
q<number>(8).then(x => console.log(x.toExponential()));
|
||||
|
||||
var delay = function (delay) {
|
||||
var d = q.defer();
|
||||
@@ -44,7 +44,7 @@ q.fcall(function () { })
|
||||
// Handle any error from step1 through step4
|
||||
}).done();
|
||||
|
||||
q.allResolved([]).then(function (promises) {
|
||||
q.allResolved([]).then(function (promises: Q.Promise<any>[]) {
|
||||
promises.forEach(function (promise) {
|
||||
if (promise.isFulfilled()) {
|
||||
var value = promise.valueOf();
|
||||
|
||||
Reference in New Issue
Block a user