promises-a-plus: added initial defintions

rx.js: modified IPromise in Async module to match Promises/A+
This commit is contained in:
Igor Oleinikov
2014-03-07 14:07:28 +04:00
parent f0946ebcda
commit 87cd95fd92
3 changed files with 60 additions and 3 deletions
+41
View File
@@ -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);
}
+16
View File
@@ -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>;
}
}
+3 -3
View File
@@ -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>;
}
}