mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-29 11:12:23 +08:00
promises-a-plus: added initial defintions
rx.js: modified IPromise in Async module to match Promises/A+
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/// <reference path="promises-a-plus.d.ts"/>
|
||||
/// <reference path="../rx.js/rx.async.d.ts"/>
|
||||
|
||||
var thenNum: PromisesAPlus.Thenable<number>;
|
||||
var thenStr: PromisesAPlus.Thenable<string>;
|
||||
var thenBool: PromisesAPlus.Thenable<boolean>;
|
||||
|
||||
var impl: PromisesAPlus.PromiseImpl;
|
||||
|
||||
declare class PromiseImpl<R> {
|
||||
constructor(resolver: (resolvePromise: (value: R) => void, rejectPromise: (reason: any) => void) => void);
|
||||
|
||||
then<U>(onFulfill: (value: R) => PromiseImpl<U>, onReject: (error: any) => PromiseImpl<U>): PromiseImpl<U>;
|
||||
then<U>(onFulfill: (value: R) => PromiseImpl<U>, onReject?: (error: any) => U): PromiseImpl<U>;
|
||||
then<U>(onFulfill: (value: R) => U, onReject: (error: any) => PromiseImpl<U>): PromiseImpl<U>;
|
||||
then<U>(onFulfill?: (value: R) => U, onReject?: (error: any) => U): PromiseImpl<U>;
|
||||
}
|
||||
|
||||
function testCompatibleWithPromiseImpl() {
|
||||
var pNum: PromiseImpl<number> = thenNum;
|
||||
|
||||
thenNum = pNum;
|
||||
|
||||
impl = PromiseImpl;
|
||||
}
|
||||
|
||||
function testCompatibleWithRxJS() {
|
||||
// from spec to Rx
|
||||
var rxThenNum: Rx.IPromise<number> = thenNum;
|
||||
var rxThenStr: Rx.IPromise<string> = thenStr;
|
||||
|
||||
// from Rx to spec
|
||||
thenNum = rxThenNum;
|
||||
thenStr = rxThenStr;
|
||||
|
||||
var obsNum: Rx.Observable<number>;
|
||||
|
||||
thenNum = obsNum.toPromise<PromisesAPlus.Thenable<number>>(impl);
|
||||
thenNum = obsNum.toPromise(impl);
|
||||
obsNum.toPromise(PromiseImpl);
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
declare module PromisesAPlus {
|
||||
interface PromiseCtor {
|
||||
<T>(resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void): Thenable<T>;
|
||||
}
|
||||
|
||||
interface PromiseImpl {
|
||||
new <T>(resolver: (resolvePromise: (value: T) => void, rejectPromise: (reason: any) => void) => void): Thenable<T>;
|
||||
}
|
||||
|
||||
interface Thenable<R> {
|
||||
then<U>(onFulfill: (value: R) => Thenable<U>, onReject: (error: any) => Thenable<U>): Thenable<U>;
|
||||
then<U>(onFulfill: (value: R) => Thenable<U>, onReject?: (error: any) => U): Thenable<U>;
|
||||
then<U>(onFulfill: (value: R) => U, onReject: (error: any) => Thenable<U>): Thenable<U>;
|
||||
then<U>(onFulfill?: (value: R) => U, onReject?: (error: any) => U): Thenable<U>;
|
||||
}
|
||||
}
|
||||
Vendored
+3
-3
@@ -104,9 +104,9 @@ declare module Rx {
|
||||
* Promise A+
|
||||
*/
|
||||
export interface IPromise<T> {
|
||||
then<R>(onFulfilled?: (value: T) => IPromise<R>, onRejected?: (reason: any) => IPromise<R>): IPromise<R>;
|
||||
then<R>(onFulfilled?: (value: T) => IPromise<R>, onRejected?: (reason: any) => R): IPromise<R>;
|
||||
then<R>(onFulfilled?: (value: T) => R, onRejected?: (reason: any) => IPromise<R>): IPromise<R>;
|
||||
then<R>(onFulfilled: (value: T) => IPromise<R>, onRejected: (reason: any) => IPromise<R>): IPromise<R>;
|
||||
then<R>(onFulfilled: (value: T) => IPromise<R>, onRejected?: (reason: any) => R): IPromise<R>;
|
||||
then<R>(onFulfilled: (value: T) => R, onRejected: (reason: any) => IPromise<R>): IPromise<R>;
|
||||
then<R>(onFulfilled?: (value: T) => R, onRejected?: (reason: any) => R): IPromise<R>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user