Added types all over the place in Q

This commit is contained in:
Andrew Gaspar
2013-07-03 00:24:15 -07:00
parent 84b94b51cb
commit 6fb97f40bf
2 changed files with 103 additions and 34 deletions
+16 -3
View File
@@ -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());