diff --git a/q/Q-tests.ts b/q/Q-tests.ts
index 34cde9341..65a19d008 100644
--- a/q/Q-tests.ts
+++ b/q/Q-tests.ts
@@ -1,5 +1,7 @@
///
+Q(8).then(x => console.log(x));
+
var delay = function (delay) {
var d = Q.defer();
setTimeout(d.resolve, delay);
diff --git a/q/Q.d.ts b/q/Q.d.ts
index 15f3fdea7..f1835241d 100644
--- a/q/Q.d.ts
+++ b/q/Q.d.ts
@@ -35,30 +35,36 @@ interface Qpromise {
valueOf(): any;
}
-interface QStatic {
- when(value: any, onFulfilled?: Function, onRejected?: Function): Qpromise;
- try(method: Function, ...args: any[]): Qpromise;
- fbind(method: Function, ...args: any[]): Qpromise;
- fcall(method: Function, ...args: any[]): Qpromise;
- all(promises: Qpromise[]): Qpromise;
- allResolved(promises: Qpromise[]): Qpromise;
- resolve(object:any):Qpromise;
- spread(onFulfilled: Function, onRejected: Function): Qpromise;
- timeout(ms: number): Qpromise;
- delay(ms: number): Qpromise;
- delay(value: any, ms: number): Qpromise;
- isFulfilled(): bool;
- isRejected(): bool;
- isPending(): bool;
- valueOf(): any;
- defer(): Qdeferred;
- (value: any): Qpromise;
- reject(): Qpromise;
- promise(factory: { resolve: Function; reject: Function; notify: Function; }): Qpromise;
- isPromise(value: any): bool;
- async(generatorFunction: any): Qdeferred;
- nextTick(callback: Function);
- oneerror: any;
- longStackJumpLimit: number;
+declare function Q(value: any): Qpromise;
+declare module Q {
+ export function when(value: any, onFulfilled: Function, onRejected?: Function): Qpromise;
+ //export function try(method: Function, ...args: any[]): Qpromise; <- This is broken currently - not sure how to fix.
+ export function fbind(method: Function, ...args: any[]): Qpromise;
+ export function fcall(method: Function, ...args: any[]): Qpromise;
+ export function nfbind(nodeFunction: Function): (...args: any[]) => Qpromise;
+ export function nfcall(nodeFunction: Function, ...args: any[]): Qpromise;
+ export function ninvoke(nodeModule: any, functionName: string, ...args: any[]): Qpromise;
+ export function all(promises: Qpromise[]): Qpromise;
+ export function allResolved(promises: Qpromise[]): Qpromise;
+ export function spread(onFulfilled: Function, onRejected: Function): Qpromise;
+ export function timeout(ms: number): Qpromise;
+ export function delay(ms: number): Qpromise;
+ export function delay(value: any, ms: number): Qpromise;
+ export function isFulfilled(): bool;
+ export function isRejected(): bool;
+ export function isPending(): bool;
+ export function valueOf(): any;
+ export function defer(): Qdeferred;
+ export function reject(): Qpromise;
+ export function promise(factory: { resolve: Function; reject: Function; notify: Function; }): Qpromise;
+ export function isPromise(value: any): bool;
+ export function async(generatorFunction: any): Qdeferred;
+ export function nextTick(callback: Function);
+ export var oneerror: any;
+ export var longStackJumpLimit: number;
+ export function resolve(object?: Qpromise);
}
-declare var Q: QStatic;
+
+declare module "q" {
+ export = Q;
+}
\ No newline at end of file
diff --git a/q/q.module-tests.ts b/q/q.module-tests.ts
index 4f9039d23..2d32febca 100644
--- a/q/q.module-tests.ts
+++ b/q/q.module-tests.ts
@@ -1,30 +1,32 @@
-///
+///
///
///
-import Q = module("q");
+import q = module("q");
import fs = module("fs");
+q(8).then(x => console.log(x));
+
var delay = function (delay) {
- var d = Q.defer();
+ var d = q.defer();
setTimeout(d.resolve, delay);
return d.promise;
};
-Q.when(delay(1000), function () {
+q.when(delay(1000), function () {
console.log('Hello, World!');
});
var eventually = function (eventually) {
- return Q.delay(eventually, 1000);
+ return q.delay(eventually, 1000);
};
-var x = Q.all([1, 2, 3].map(eventually));
-Q.when(x, function (x) {
+var x = q.all([1, 2, 3].map(eventually));
+q.when(x, function (x) {
console.log(x);
});
-Q.all([
+q.all([
eventually(10),
eventually(20)
])
@@ -32,7 +34,7 @@ Q.all([
console.log(x, y);
});
-Q.fcall(function () { })
+q.fcall(function () { })
.then(function () { })
.then(function () { })
.then(function () { })
@@ -42,7 +44,7 @@ Q.fcall(function () { })
// Handle any error from step1 through step4
}).done();
-Q.allResolved([])
+q.allResolved([])
.then(function (promises: Qpromise[]) {
promises.forEach(function (promise) {
if (promise.isFulfilled()) {
@@ -55,20 +57,20 @@ Q.allResolved([])
var initialVal: any;
var funcs = ['foo', 'bar', 'baz', 'qux'];
-var result = Q.resolve(initialVal);
+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.nfcall(fs.readFile, "foo.txt", "utf-8").then(replaceText);
-Q.ninvoke(fs, "readFile", "foo.txt", "utf-8").then(replaceText);
+q.ninvoke(fs, "readFile", "foo.txt", "utf-8").then(replaceText);
-var deferred = Q.defer();
+var deferred = q.defer();
fs.readFile("foo.txt", "utf-8", deferred.makeNodeResolver());
deferred.promise.then(replaceText);
-var readFile = Q.nfbind(fs.readFile);
+var readFile = q.nfbind(fs.readFile);
readFile("foo.txt", "utf-8").then(replaceText);
\ No newline at end of file
diff --git a/q/q.module.d.ts b/q/q.module.d.ts
deleted file mode 100644
index 98e1dd9dc..000000000
--- a/q/q.module.d.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-///
-
-declare module "q" {
- export function when(value: any, onFulfilled: Function, onRejected?: Function): Qpromise;
- export function try(method: Function, ...args: any[]): Qpromise;
- export function fbind(method: Function, ...args: any[]): Qpromise;
- export function fcall(method: Function, ...args: any[]): Qpromise;
- export function nfbind(nodeFunction: Function): (...args: any[]) => Qpromise;
- export function nfcall(nodeFunction: Function, ...args: any[]): Qpromise;
- export function ninvoke(nodeModule: any, functionName: string, ...args: any[]): Qpromise;
- export function all(promises: Qpromise[]): Qpromise;
- export function allResolved(promises: Qpromise[]): Qpromise;
- export function spread(onFulfilled: Function, onRejected: Function): Qpromise;
- export function timeout(ms: number): Qpromise;
- export function delay(ms: number): Qpromise;
- export function delay(value: any, ms: number): Qpromise;
- export function isFulfilled(): bool;
- export function isRejected(): bool;
- export function isPending(): bool;
- export function valueOf(): any;
- export function defer(): Qdeferred;
- export function (value: any): Qpromise;
- export function reject(): Qpromise;
- export function promise(factory: { resolve: Function; reject: Function; notify: Function; }): Qpromise;
- export function isPromise(value: any): bool;
- export function async(generatorFunction: any): Qdeferred;
- export function nextTick(callback: Function);
- export var oneerror: any;
- export var longStackJumpLimit: number;
- export function resolve(object?:Qpromise);
-}
\ No newline at end of file