Skip to content

Commit

Permalink
fix(flatten): fix type inference hinting
Browse files Browse the repository at this point in the history
Makes it impossible to call flatten() on a stream of numbers, in TypeScript.
  • Loading branch information
staltz committed Jan 31, 2017
1 parent a0f0dae commit df6d720
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1932,12 +1932,12 @@ export class Stream<T> implements InternalListener<T> {
*
* @return {Stream}
*/
flatten<R>(): T {
flatten<R>(this: Stream<Stream<R>>): T {
const p = this._prod;
return new Stream<R>(
p instanceof MapOp && !(p instanceof FilterMapFusion) ?
new MapFlatten(p as MapOp<any, Stream<R>>) :
new Flatten(this as any as Stream<Stream<R>>)
new Flatten(this)
) as T & Stream<R>;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/operator/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Stream.prototype.flatten', () => {
it('should expand each periodic event with 3 sync events', (done: any) => {
const source: Stream<Stream<number>> = xs.periodic(100).take(3)
.map((i: number) => xs.of(1 + i, 2 + i, 3 + i));
const stream: Stream<number> = source.flatten();
const stream = source.flatten();
const expected = [1, 2, 3, 2, 3, 4, 3, 4, 5];

stream.addListener({
Expand Down

0 comments on commit df6d720

Please sign in to comment.