mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-29 11:12:23 +08:00
Removed separate q module tests and updated with some addition typing information for Q.d.ts.
This commit is contained in:
+10
-7
@@ -1,5 +1,7 @@
|
||||
/// <reference path="Q.d.ts" />
|
||||
|
||||
import q = module('q');
|
||||
|
||||
Q(8).then(x => console.log(x.toExponential()));
|
||||
|
||||
var delay = function (delay: number) {
|
||||
@@ -12,6 +14,14 @@ Q.when(delay(1000), function () {
|
||||
console.log('Hello, World!');
|
||||
});
|
||||
|
||||
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);
|
||||
Q.delay("asdf", 1000).then(x => x.length);
|
||||
|
||||
var eventualAdd = Q.promised((a: number, b: number) => a + b);
|
||||
eventualAdd(Q(1), Q(2)).then(x => x.toExponential());
|
||||
|
||||
var eventually = function (eventually) {
|
||||
return Q.delay(eventually, 1000);
|
||||
};
|
||||
@@ -48,11 +58,4 @@ Q.allResolved([])
|
||||
var exception = promise.valueOf().exception;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var initialVal: any;
|
||||
var funcs = ['foo', 'bar', 'baz', 'qux'];
|
||||
var result = Q.resolve(initialVal);
|
||||
funcs.forEach(function (f) {
|
||||
result = result.then(f);
|
||||
});
|
||||
@@ -16,22 +16,23 @@ declare module Q {
|
||||
|
||||
interface Promise<T> {
|
||||
fail(errorCallback: Function): Promise<any>;
|
||||
fin(finallyCallback: Function): Promise<any>;
|
||||
fin(finallyCallback: Function): Promise<T>;
|
||||
finally(finallyCallback: Function): Promise<T>;
|
||||
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>;
|
||||
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>;
|
||||
keys(): Promise<any>;
|
||||
keys(): Promise<string[]>;
|
||||
fapply(args: any[]): Promise<any>;
|
||||
fcall(method: Function, ...args: any[]): Promise<any>;
|
||||
timeout(ms: number): Promise<any>;
|
||||
delay(ms: number): Promise<any>;
|
||||
timeout(ms: number, message?): Promise<T>;
|
||||
delay(ms: number): Promise<T>;
|
||||
isFulfilled(): bool;
|
||||
isRejected(): bool;
|
||||
isPending(): bool;
|
||||
@@ -48,22 +49,25 @@ declare module Q {
|
||||
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 timeout<T>(promise: Promise<T>, ms: number, message?): 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>): bool;
|
||||
export function isRejected(promise: Promise<any>): bool;
|
||||
export function isPending(promise: Promise<any>): bool;
|
||||
export function valueOf<T>(promise: Promise<T>): T;
|
||||
export function defer<T>(): Deferred<T>;
|
||||
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<any>);
|
||||
export function reject(reason?): Promise<any>;
|
||||
export function promise<T>(factory: { resolve: Function; reject: Function; notify: Function; }): Promise<T>;
|
||||
export function promised<T>(callback: (...any) => T): (...any) => Promise<T>;
|
||||
export function isPromise(object): bool;
|
||||
export function isPromiseAlike(object): bool;
|
||||
export function isPending(object): bool;
|
||||
export function async<T>(generatorFunction: any): (...args) => Promise<T>;
|
||||
export function nextTick(callback: Function): void;
|
||||
export var oneerror: () => void;
|
||||
export var longStackSupport: bool;
|
||||
export function resolve<T>(object): Promise<T>;
|
||||
}
|
||||
|
||||
declare module "q" {
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/// <reference path="q.d.ts" />
|
||||
/// <reference path="../jasmine/jasmine.d.ts" />
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
import q = module("q");
|
||||
import fs = module("fs");
|
||||
|
||||
q<number>(8).then(x => console.log(x.toExponential()));
|
||||
|
||||
var delay = function (delay) {
|
||||
var d = q.defer();
|
||||
setTimeout(d.resolve, delay);
|
||||
return d.promise;
|
||||
};
|
||||
|
||||
q.when(delay(1000), function () {
|
||||
console.log('Hello, World!');
|
||||
});
|
||||
|
||||
var eventually = function (eventually) {
|
||||
return q.delay(eventually, 1000);
|
||||
};
|
||||
|
||||
var x = q.all([1, 2, 3].map(eventually));
|
||||
q.when(x, function (x) {
|
||||
console.log(x);
|
||||
});
|
||||
|
||||
q.all([
|
||||
eventually(10),
|
||||
eventually(20)
|
||||
])
|
||||
.spread(function (x, y) {
|
||||
console.log(x, y);
|
||||
});
|
||||
|
||||
q.fcall(function () { })
|
||||
.then(function () { })
|
||||
.then(function () { })
|
||||
.then(function () { })
|
||||
.then(function (value4) {
|
||||
// Do something with value4
|
||||
}, function (error) {
|
||||
// Handle any error from step1 through step4
|
||||
}).done();
|
||||
|
||||
q.allResolved([]).then(function (promises: Q.Promise<any>[]) {
|
||||
promises.forEach(function (promise) {
|
||||
if (promise.isFulfilled()) {
|
||||
var value = promise.valueOf();
|
||||
} else {
|
||||
var exception = promise.valueOf().exception;
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var initialVal: any;
|
||||
var funcs = ['foo', 'bar', 'baz', 'qux'];
|
||||
var result = q.resolve(initialVal);
|
||||
funcs.forEach(function (f) {
|
||||
result = result.then(f);
|
||||
});
|
||||
|
||||
var replaceText = (text: string) => text.replace("a", "b");
|
||||
|
||||
q.nfcall(fs.readFile, "foo.txt", "utf-8").then(replaceText);
|
||||
|
||||
q.ninvoke(fs, "readFile", "foo.txt", "utf-8").then(replaceText);
|
||||
|
||||
var deferred = q.defer<string>();
|
||||
fs.readFile("foo.txt", "utf-8", deferred.makeNodeResolver());
|
||||
deferred.promise.then(replaceText);
|
||||
|
||||
var readFile = q.nfbind(fs.readFile);
|
||||
readFile("foo.txt", "utf-8").then(replaceText);
|
||||
Reference in New Issue
Block a user