-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(typings): fix typings for error prone operators like concatAll #2690
Conversation
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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line endings?
There was a problem hiding this comment.
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 :(
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :(
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see ... looks good.
d2c6c5c
to
430991d
Compare
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
430991d
to
495bfb7
Compare
This also has changes that help with #1633 |
|
||
export const rxTestScheduler: TestScheduler = global.rxTestScheduler; | ||
|
||
export function hot(marbles: string, values?: void, error?: any): HotObservable<string>; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
0804bcf
to
495bfb7
Compare
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. |
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