mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
angularjs: added $q tests
This commit is contained in:
@@ -244,17 +244,69 @@ foo.then((x) => {
|
||||
|
||||
// $q signature tests
|
||||
module TestQ {
|
||||
var $q: ng.IQService;
|
||||
var promise1: ng.IPromise<any>;
|
||||
var promise2: ng.IPromise<any>;
|
||||
interface TResult {
|
||||
a: number;
|
||||
b: string;
|
||||
c: boolean;
|
||||
}
|
||||
var tResult: TResult;
|
||||
var promiseTResult: angular.IPromise<TResult>;
|
||||
|
||||
var $q: angular.IQService;
|
||||
var promiseAny: angular.IPromise<any>;
|
||||
|
||||
// $q constructor
|
||||
{
|
||||
let result: angular.IPromise<TResult>;
|
||||
result = new $q<TResult>((resolve: (value: TResult) => any) => {});
|
||||
result = new $q<TResult>((resolve: (value: TResult) => any, reject: (value: any) => any) => {});
|
||||
}
|
||||
|
||||
// $q.all
|
||||
$q.all([promise1, promise2]).then((results: any[]) => {});
|
||||
$q.all<number>([promise1, promise2]).then((results: number[]) => {});
|
||||
$q.all({a: promise1, b: promise2}).then((results: {[id: string]: any;}) => {});
|
||||
$q.all<{a: number; b: string;}>({a: promise1, b: promise2}).then((results: {a: number; b: string;}) => {});
|
||||
{
|
||||
let result: angular.IPromise<any[]>;
|
||||
result = $q.all([promiseAny, promiseAny]);
|
||||
}
|
||||
{
|
||||
let result: angular.IPromise<TResult[]>;
|
||||
result = $q.all<TResult>([promiseAny, promiseAny]);
|
||||
}
|
||||
{
|
||||
let result: angular.IPromise<{[id: string]: any;}>;
|
||||
result = $q.all({a: promiseAny, b: promiseAny});
|
||||
}
|
||||
{
|
||||
let result: angular.IPromise<{a: number; b: string;}>;
|
||||
result = $q.all<{a: number; b: string;}>({a: promiseAny, b: promiseAny});
|
||||
}
|
||||
|
||||
|
||||
// $q.defer
|
||||
{
|
||||
let result: angular.IDeferred<TResult>;
|
||||
result = $q.defer<TResult>();
|
||||
}
|
||||
|
||||
// $q.reject
|
||||
{
|
||||
let result: angular.IPromise<any>;
|
||||
result = $q.reject();
|
||||
result = $q.reject('');
|
||||
}
|
||||
|
||||
// $q.when
|
||||
{
|
||||
let result: angular.IPromise<void>;
|
||||
result = $q.when();
|
||||
}
|
||||
{
|
||||
let result: angular.IPromise<TResult>;
|
||||
result = $q.when<TResult>(tResult);
|
||||
result = $q.when<TResult>(promiseTResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var httpFoo: ng.IHttpPromise<number>;
|
||||
httpFoo.then((x) => {
|
||||
// When returning a promise the generic type must be inferred.
|
||||
|
||||
Reference in New Issue
Block a user