mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Angular IPromise interop with platform Promise.
Angular promises support `.then()` chaining of functions that return
arbitrary `then()`able values.
https://docs.angularjs.org/api/ng/service/$q#the-promise-api
This change updates the definition of `ng.IPromise.then()` to match that
by overloading the function to handle `PromiseLike` values.
This commit is contained in:
parent
ab0806bfb5
commit
970fc9d484
@ -294,6 +294,14 @@ foo.then((x) => {
|
||||
x.toFixed();
|
||||
});
|
||||
|
||||
namespace TestPromiseInterop {
|
||||
declare const promiseInterop: ng.IPromise<number>;
|
||||
const ngStringPromise: ng.IPromise<string> =
|
||||
promiseInterop.then((num) => Promise.resolve(String(num)));
|
||||
const caughtStringPromise: ng.IPromise<string|number> =
|
||||
promiseInterop.catch((reason) => Promise.resolve('oh noes'));
|
||||
}
|
||||
|
||||
// $q signature tests
|
||||
namespace TestQ {
|
||||
interface AbcObject {
|
||||
|
||||
14
types/angular/index.d.ts
vendored
14
types/angular/index.d.ts
vendored
@ -1197,6 +1197,15 @@ declare namespace angular {
|
||||
* the `notifyCallback` method. The promise can not be resolved or rejected from the
|
||||
* `notifyCallback` method.
|
||||
*/
|
||||
then<TResult1 = T, TResult2 = never>(
|
||||
successCallback?:
|
||||
| ((value: T) => PromiseLike<never> | PromiseLike<TResult1> | TResult1)
|
||||
| null,
|
||||
errorCallback?:
|
||||
| ((reason: any) => PromiseLike<never> | PromiseLike<TResult2> | TResult2)
|
||||
| null,
|
||||
notifyCallback?: (state: any) => any
|
||||
): IPromise<TResult1 | TResult2>;
|
||||
then<TResult1 = T, TResult2 = never>(
|
||||
successCallback?:
|
||||
| ((value: T) => IPromise<never> | IPromise<TResult1> | TResult1)
|
||||
@ -1210,6 +1219,11 @@ declare namespace angular {
|
||||
/**
|
||||
* Shorthand for promise.then(null, errorCallback)
|
||||
*/
|
||||
catch<TResult = never>(
|
||||
onRejected?:
|
||||
| ((reason: any) => PromiseLike<never> | PromiseLike<TResult> | TResult)
|
||||
| null
|
||||
): IPromise<T | TResult>;
|
||||
catch<TResult = never>(
|
||||
onRejected?:
|
||||
| ((reason: any) => IPromise<never> | IPromise<TResult> | TResult)
|
||||
|
||||
@ -11,7 +11,8 @@
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.iterable"
|
||||
"es2015.iterable",
|
||||
"es2015.promise"
|
||||
],
|
||||
"noImplicitAny": false,
|
||||
"noImplicitThis": false,
|
||||
@ -25,4 +26,4 @@
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user