mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-24 05:47:44 +08:00
Added types all over the place in Q
This commit is contained in:
19
q/Q-tests.ts
19
q/Q-tests.ts
@@ -6,15 +6,18 @@ import q = module('q');
|
||||
Q(8).then(x => console.log(x.toExponential()));
|
||||
|
||||
var delay = function (delay: number) {
|
||||
var d = Q.defer();
|
||||
var d = Q.defer<void>();
|
||||
setTimeout(d.resolve, delay);
|
||||
return d.promise;
|
||||
};
|
||||
|
||||
Q.when(delay(1000), function () {
|
||||
Q.when(delay(1000), function (val: void) {
|
||||
console.log('Hello, World!');
|
||||
return;
|
||||
});
|
||||
|
||||
Q.timeout(Q(new Date()), 1000, "My dates never arrived. :(").then(d => d.toJSON());
|
||||
|
||||
Q.delay(Q(8), 1000).then(x => x.toExponential());
|
||||
Q.delay(8, 1000).then(x => x.toExponential());
|
||||
Q.delay(Q("asdf"), 1000).then(x => x.length);
|
||||
@@ -73,4 +76,14 @@ Q<number[]>(arrayPromise) // type specification required
|
||||
declare var jPromise: JQueryPromise;
|
||||
|
||||
// if jQuery promises definition supported generics, this could be more interesting example
|
||||
Q<any>(jPromise).then((val) => val.toExponential());
|
||||
Q<any>(jPromise).then((val) => val.toExponential());
|
||||
|
||||
declare var promiseArray: Q.IPromise<number>[];
|
||||
var qPromiseArray = promiseArray.map(p => Q<number>(p));
|
||||
var myNums: any[] = [2, 3, Q(4), 5, Q(6), Q(7)];
|
||||
|
||||
Q.all(promiseArray).then(nums => nums.map(num => num.toPrecision(2)).join(','));
|
||||
|
||||
Q.all<number>(myNums).then(nums => nums.map(Math.round));
|
||||
|
||||
Q.fbind((dateString) => new Date(dateString), "11/11/1991")().then(d => d.toLocaleDateString());
|
||||
118
q/Q.d.ts
vendored
118
q/Q.d.ts
vendored
@@ -16,71 +16,127 @@ declare module Q {
|
||||
|
||||
interface Deferred<T> {
|
||||
promise: Promise<T>;
|
||||
resolve(value: T): any;
|
||||
reject(reason: any);
|
||||
notify(value: any);
|
||||
resolve(value: T): void;
|
||||
reject(reason: any): void;
|
||||
notify(value: any): void;
|
||||
makeNodeResolver(): (reason, value: T) => void;
|
||||
}
|
||||
|
||||
interface Promise<T> {
|
||||
fail(errorCallback: Function): Promise<any>;
|
||||
fin(finallyCallback: Function): Promise<T>;
|
||||
finally(finallyCallback: Function): Promise<T>;
|
||||
fin(finallyCallback: () => any): Promise<T>;
|
||||
finally(finallyCallback: () => any): Promise<T>;
|
||||
|
||||
then<U>(onFulfill: (value: T) => U, onReject?: (reason) => U, onProgress?: Function): Promise<U>;
|
||||
then<U>(onFulfill: (value: T) => IPromise<U>, onReject?: (reason) => U, onProgress?: Function): Promise<U>;
|
||||
then<U>(onFulfill: (value: T) => U, onReject?: (reason) => IPromise<U>, onProgress?: Function): Promise<U>;
|
||||
then<U>(onFulfill: (value: T) => IPromise<U>, onReject?: (reason) => IPromise<U>, onProgress?: Function): Promise<U>;
|
||||
|
||||
spread(onFulfilled: Function, onRejected?: Function): Promise<any>;
|
||||
catch(onRejected: Function): Promise<any>;
|
||||
progress(onProgress: Function): Promise<any>;
|
||||
done(onFulfilled?: Function, onRejected?: Function, onProgress?: Function): void;
|
||||
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>;
|
||||
spread<U>(onFulfilled: Function, onRejected?: Function): Promise<U>;
|
||||
|
||||
fail<U>(onRejected: (reason) => U): Promise<U>;
|
||||
fail<U>(onRejected: (reason) => IPromise<U>): Promise<U>;
|
||||
catch<U>(onRejected: (reason) => U): Promise<U>;
|
||||
catch<U>(onRejected: (reason) => IPromise<U>): Promise<U>;
|
||||
|
||||
progress(onProgress: (progress) => any): Promise<T>;
|
||||
|
||||
done(onFulfilled?: (value: T) => any, onRejected?: (reason) => any, onProgress?: (progress) => any): void;
|
||||
|
||||
get<U>(propertyName: String): Promise<U>;
|
||||
set<U>(propertyName: String, value: any): Promise<U>;
|
||||
delete<U>(propertyName: String): Promise<U>;
|
||||
post<U>(methodName: String, args: any[]): Promise<U>;
|
||||
invoke<U>(methodName: String, ...args: any[]): Promise<U>;
|
||||
fapply<U>(args: any[]): Promise<U>;
|
||||
fcall<U>(...args: any[]): Promise<U>;
|
||||
|
||||
keys(): Promise<string[]>;
|
||||
fapply(args: any[]): Promise<any>;
|
||||
fcall(method: Function, ...args: any[]): Promise<any>;
|
||||
timeout(ms: number, message?): Promise<T>;
|
||||
|
||||
timeout(ms: number, message?: string): Promise<T>;
|
||||
delay(ms: number): Promise<T>;
|
||||
|
||||
isFulfilled(): boolean;
|
||||
isRejected(): boolean;
|
||||
isPending(): boolean;
|
||||
|
||||
valueOf(): any;
|
||||
}
|
||||
|
||||
export function when(value: any, onFulfilled: Function, onRejected?: Function): Promise<any>;
|
||||
export function when<T>(value: T): Promise<T>;
|
||||
export function when<T>(value: IPromise<T>): Promise<T>;
|
||||
export function when<T, U>(value: T, onFulfilled: (val: T) => U): Promise<U>;
|
||||
export function when<T, U>(value: T, onFulfilled: (val: T) => IPromise<U>): Promise<U>;
|
||||
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => U, onRejected?: (reason) => U): Promise<U>;
|
||||
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => IPromise<U>, onRejected?: (reason) => U): Promise<U>;
|
||||
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => U, onRejected?: (reason) => IPromise<U>): Promise<U>;
|
||||
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => IPromise<U>, onRejected?: (reason) => IPromise<U>): Promise<U>;
|
||||
|
||||
//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<T>(promise: Promise<T>, ms: number, message?): Promise<T>;
|
||||
|
||||
export function fbind<T>(method: (...args: any[]) => T, ...args: any[]): (...args: any[]) => Promise<T>;
|
||||
export function fbind<T>(method: (...args: any[]) => IPromise<T>, ...args: any[]): (...args: any[]) => Promise<T>;
|
||||
|
||||
export function fcall<T>(method: (...args) => T, ...args: any[]): Promise<T>;
|
||||
|
||||
export function send<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
|
||||
export function invoke<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
|
||||
export function mcall<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
|
||||
|
||||
export function nfbind<T>(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise<T>;
|
||||
export function nfcall<T>(nodeFunction: Function, ...args: any[]): Promise<T>;
|
||||
|
||||
export function ninvoke<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>;
|
||||
export function nsend<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>;
|
||||
export function nmcall<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>;
|
||||
|
||||
export function all<T>(promises: any[]): Promise<T[]>;
|
||||
export function all<T>(promises: IPromise<T>[]): Promise<T[]>;
|
||||
|
||||
export function allSettled<T>(promises: any[]): Promise<Promise<T>[]>;
|
||||
export function allSettled<T>(promises: IPromise<T>[]): Promise<Promise<T>[]>;
|
||||
|
||||
export function allResolved<T>(promises: any[]): Promise<Promise<T>[]>;
|
||||
export function allResolved<T>(promises: IPromise<T>[]): Promise<Promise<T>[]>;
|
||||
|
||||
export function spread<U>(promises: any[], onFulfilled: (...args: any[]) => U, onRejected: (reason) => U): Promise<U>;
|
||||
export function spread<U>(promises: any[], onFulfilled: (...args: any[]) => IPromise<U>, onRejected: (reason) => U): Promise<U>;
|
||||
export function spread<U>(promises: any[], onFulfilled: (...args: any[]) => U, onRejected: (reason) => IPromise<U>): Promise<U>;
|
||||
export function spread<U>(promises: any[], onFulfilled: (...args: any[]) => IPromise<U>, onRejected: (reason) => IPromise<U>): Promise<U>;
|
||||
export function spread<T, U>(promises: IPromise<T>[], onFulfilled: (...args: T[]) => U, onRejected: (reason) => U): Promise<U>;
|
||||
export function spread<T, U>(promises: IPromise<T>[], onFulfilled: (...args: T[]) => IPromise<U>, onRejected: (reason) => U): Promise<U>;
|
||||
export function spread<T, U>(promises: IPromise<T>[], onFulfilled: (...args: T[]) => U, onRejected: (reason) => IPromise<U>): Promise<U>;
|
||||
export function spread<T, U>(promises: IPromise<T>[], onFulfilled: (...args: T[]) => IPromise<U>, onRejected: (reason) => IPromise<U>): Promise<U>;
|
||||
|
||||
export function timeout<T>(promise: Promise<T>, ms: number, message?: string): Promise<T>;
|
||||
|
||||
export function delay<T>(promise: Promise<T>, ms: number): Promise<T>;
|
||||
export function delay<T>(value: T, ms: number): Promise<T>;
|
||||
|
||||
export function isFulfilled(promise: Promise<any>): boolean;
|
||||
export function isRejected(promise: Promise<any>): boolean;
|
||||
export function isPending(promise: Promise<any>): boolean;
|
||||
export function valueOf<T>(promise: Promise<T>): T;
|
||||
|
||||
export function defer<T>(): Deferred<T>;
|
||||
|
||||
export function reject(reason?): Promise<any>;
|
||||
export function promise<T>(factory: { resolve: Function; reject: Function; notify: Function; }): Promise<T>;
|
||||
|
||||
export function promise<T>(resolver: (resolve: (val: T) => void , reject: (reason) => void , notify: (progress) => void ) => void ): Promise<T>;
|
||||
export function promise<T>(resolver: (resolve: (val: IPromise<T>) => void , reject: (reason) => void , notify: (progress) => void ) => void ): Promise<T>;
|
||||
|
||||
export function promised<T>(callback: (...any) => T): (...any) => Promise<T>;
|
||||
|
||||
export function isPromise(object): boolean;
|
||||
export function isPromiseAlike(object): boolean;
|
||||
export function isPending(object): boolean;
|
||||
|
||||
export function async<T>(generatorFunction: any): (...args) => Promise<T>;
|
||||
export function nextTick(callback: Function): void;
|
||||
|
||||
export var oneerror: () => void;
|
||||
export var longStackSupport: boolean;
|
||||
export function resolve<T>(object): Promise<T>;
|
||||
|
||||
export function resolve<T>(object: T): Promise<T>;
|
||||
export function resolve<T>(object: IPromise<T>): Promise<T>;
|
||||
}
|
||||
|
||||
declare module "q" {
|
||||
|
||||
Reference in New Issue
Block a user