angular: gave a more precise return type to $q.all<T>()

This commit is contained in:
Kasper Guldmann Nielsen
2017-06-21 18:15:00 +02:00
parent 5c0f7336fb
commit 2effeac8f0
14 changed files with 31 additions and 1 deletions

View File

@@ -337,6 +337,16 @@ namespace TestQ {
let result: angular.IPromise<{a: number; b: string; }>;
result = $q.all<{a: number; b: string; }>({a: promiseAny, b: promiseAny});
}
{
let result = $q.all({ num: $q.when(2), str: $q.when('test') });
// TS should infer that num is a number and str is a string
result.then(r => (r.num * 2) + r.str.indexOf('s'));
}
{
let result = $q.all({ num: $q.when(2), str: 'test' });
// TS should infer that num is a number and str is a string
result.then(r => (r.num * 2) + r.str.indexOf('s'));
}
// $q.defer
{

View File

@@ -1029,7 +1029,7 @@ declare namespace angular {
*
* @param promises A hash of promises.
*/
all<T extends {}>(promises: { [K in keyof T]: IPromise<T[K]>; }): IPromise<T>;
all<T>(promises: { [K in keyof T]: (IPromise<T[K]> | T[K]); }): IPromise<T>;
/**
* Creates a Deferred object which represents a task which will finish in the future.
*/