Fixes #2788 Correctly declare the return type of promise.filter and promise.map

This commit is contained in:
Nick Fisher
2014-09-08 17:09:41 +02:00
parent 50dd84eb5d
commit 310d3afe0d
2 changed files with 8 additions and 8 deletions
+4 -4
View File
@@ -477,10 +477,10 @@ barProm = fooProm.race<Bar>();
//TODO fix collection inference
barProm = fooProm.map<Foo, Bar>((item: Foo, index: number, arrayLength: number) => {
barArrProm = fooProm.map<Foo, Bar>((item: Foo, index: number, arrayLength: number) => {
return bar;
});
barProm = fooProm.map<Foo, Bar>((item: Foo) => {
barArrProm = fooProm.map<Foo, Bar>((item: Foo) => {
return bar;
});
@@ -495,10 +495,10 @@ barProm = fooProm.reduce<Foo, Bar>((memo: Bar, item: Foo) => {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fooProm = fooProm.filter<Foo>((item: Foo, index: number, arrayLength: number) => {
fooArrProm = fooArrProm.filter<Foo>((item: Foo, index: number, arrayLength: number) => {
return bool;
});
fooProm = fooProm.filter<Foo>((item: Foo) => {
fooArrProm = fooArrProm.filter<Foo>((item: Foo) => {
return bool;
});
+4 -4
View File
@@ -296,8 +296,8 @@ declare class Promise<R> implements Promise.Thenable<R> {
* Same as calling `Promise.map(thisPromise, mapper)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
// TODO type inference from array-resolving promise?
map<Q, U>(mapper: (item: Q, index: number, arrayLength: number) => Promise.Thenable<U>): Promise<U>;
map<Q, U>(mapper: (item: Q, index: number, arrayLength: number) => U): Promise<U>;
map<Q, U>(mapper: (item: Q, index: number, arrayLength: number) => Promise.Thenable<U>): Promise<U[]>;
map<Q, U>(mapper: (item: Q, index: number, arrayLength: number) => U): Promise<U[]>;
/**
* Same as calling `Promise.reduce(thisPromise, Function reducer, initialValue)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
@@ -310,8 +310,8 @@ declare class Promise<R> implements Promise.Thenable<R> {
* Same as calling ``Promise.filter(thisPromise, filterer)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
// TODO type inference from array-resolving promise?
filter<U>(filterer: (item: U, index: number, arrayLength: number) => Promise.Thenable<boolean>): Promise<U>;
filter<U>(filterer: (item: U, index: number, arrayLength: number) => boolean): Promise<U>;
filter<U>(filterer: (item: U, index: number, arrayLength: number) => Promise.Thenable<boolean>): Promise<U[]>;
filter<U>(filterer: (item: U, index: number, arrayLength: number) => boolean): Promise<U[]>;
/**
* Start the chain of promises with `Promise.try`. Any synchronous exceptions will be turned into rejections on the returned promise.