Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typings): fix typings for error prone operators like concatAll #2690

Merged
merged 1 commit into from
Jun 27, 2017

Conversation

david-driscoll
Copy link
Member

Description:
fixes concatAll, combineAll, exhaust, mergeAll, switch, zipAll. Also made a few improvements to
how hot and cold observables are typed. A few compiler errors were fixed due to this change.

Related issue (if exists):
fixes #2658 #2493 #2551

@rxjs-bot
Copy link

rxjs-bot commented Jun 22, 2017

Warnings
⚠️ ❗ Big PR (1)

(1) : Pull Request size seems relatively large. If Pull Request contains multiple changes, split each into separate PR will helps faster, easier review.

Generated by 🚫 dangerJS

throw 'tried to use time() in async test';
}
return global.rxTestScheduler.createTime.apply(global.rxTestScheduler, arguments);
import {Observable} from '../../dist/cjs/Observable';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why this file diffed so badly... but this adds two overloads for hot and cold to help with type inference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line endings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just pushed a change to line endings and it didn't change anything :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... it's hard to review like this.

Is this maybe a thing from working on a windows machine?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had reset line endings on the file and it didn't change the diff. It diffs just fine for me locally too :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment on what's changed in this file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two new overloads for hot and cold.

export function hot(marbles: string, values?: void, error?: any): HotObservable<string>;
export function hot<V>(marbles: string, values?: { [index: string]: V; }, error?: any): HotObservable<V>;


export function cold(marbles: string, values?: void, error?: any): ColdObservable<string>;
export function cold<V>(marbles: string, values?: { [index: string]: V; }, error?: any): ColdObservable<V>;

The first overload, defaults the returned HotObservable to be a type of string (ie ColdObservable<string>)
The second overload, allows for type inference of the output observable, so that it is typed as a union of the input values.

Given a value let values = { a: 1, b: 2, c: 3 } then the type of hot('a---b---c---|', values) will then HotObservable<number>;

Given a more complex case (stolen from mergeAll-spec.ts)

it('should merge two cold Observables at a time with parameter concurrency=2', () => {
    const x = cold(     'a---b---c---|        ');
    const xsubs =     '  ^           !        ';
    const y = cold(        'd---e---f---|     ');
    const ysubs =     '     ^           !     ';
    const z = cold(                 '--g---h-|');
    const zsubs =     '              ^       !';
    const e1 =    hot('--x--y--z--|           ', { x, y, z });
    const e1subs =    '^                     !';
    const expected =  '--a--db--ec--f--g---h-|';

    expectObservable(e1.mergeAll(2)).toBe(expected);
    expectSubscriptions(x.subscriptions).toBe(xsubs);
    expectSubscriptions(y.subscriptions).toBe(ysubs);
    expectSubscriptions(z.subscriptions).toBe(zsubs);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });

Given that x, y, and z are all ColdObservable<string> the type of e1 then becomes HotObservable<ColdObservable<string>>. This then gives us proper type information in unit tests and allows removing of several corner cases where we explicitly cast to any to work around the problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see ... looks good.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.739% when pulling d2c6c5c on david-driscoll:fix/typings/concatAll into 766b5a7 on ReactiveX:next.

fixes concatAll, combineAll, exhaust, mergeAll, switch, zipAll.  Also made a few improvements to
how hot and cold observables are typed.  A few compiler errors were fixed due to this change.

fixes ReactiveX#2658 ReactiveX#2493 ReactiveX#2551
@david-driscoll
Copy link
Member Author

This also has changes that help with #1633

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.739% when pulling 495bfb7 on david-driscoll:fix/typings/concatAll into 766b5a7 on ReactiveX:next.


export const rxTestScheduler: TestScheduler = global.rxTestScheduler;

export function hot(marbles: string, values?: void, error?: any): HotObservable<string>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh, values is void type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we've used it before for things like groupBy and bindNodeCallback

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather values it void by default (if we don't give it a value), if we do give it a value we can then infer it's type.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.739% when pulling 495bfb7 on david-driscoll:fix/typings/concatAll into 766b5a7 on ReactiveX:next.

@david-driscoll david-driscoll force-pushed the fix/typings/concatAll branch 2 times, most recently from 0804bcf to 495bfb7 Compare June 23, 2017 14:31
@coveralls
Copy link

coveralls commented Jun 23, 2017

Coverage Status

Coverage remained the same at 97.739% when pulling 495bfb7 on david-driscoll:fix/typings/concatAll into 766b5a7 on ReactiveX:next.

@david-driscoll
Copy link
Member Author

any input @kwonoj @benlesh ? 🕺 💃

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants