-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(typings): fix typings for error prone operators like concatAll #2690
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,49 @@ | ||
import {Observable} from '../../dist/cjs/Observable'; | ||
import {SubscriptionLog} from '../../dist/cjs/testing/SubscriptionLog'; | ||
import {ColdObservable} from '../../dist/cjs/testing/ColdObservable'; | ||
import {HotObservable} from '../../dist/cjs/testing/HotObservable'; | ||
import {TestScheduler, observableToBeFn, subscriptionLogsToBeFn} from '../../dist/cjs/testing/TestScheduler'; | ||
|
||
declare const global: any; | ||
|
||
export const rxTestScheduler: TestScheduler = global.rxTestScheduler; | ||
|
||
export function hot(marbles: string, values?: any, error?: any): HotObservable<any> { | ||
if (!global.rxTestScheduler) { | ||
throw 'tried to use hot() in async test'; | ||
} | ||
return global.rxTestScheduler.createHotObservable.apply(global.rxTestScheduler, arguments); | ||
} | ||
|
||
export function cold(marbles: string, values?: any, error?: any): ColdObservable<any> { | ||
if (!global.rxTestScheduler) { | ||
throw 'tried to use cold() in async test'; | ||
} | ||
return global.rxTestScheduler.createColdObservable.apply(global.rxTestScheduler, arguments); | ||
} | ||
|
||
export function expectObservable(observable: Observable<any>, | ||
unsubscriptionMarbles: string = null): ({ toBe: observableToBeFn }) { | ||
if (!global.rxTestScheduler) { | ||
throw 'tried to use expectObservable() in async test'; | ||
} | ||
return global.rxTestScheduler.expectObservable.apply(global.rxTestScheduler, arguments); | ||
} | ||
|
||
export function expectSubscriptions(actualSubscriptionLogs: SubscriptionLog[]): ({ toBe: subscriptionLogsToBeFn }) { | ||
if (!global.rxTestScheduler) { | ||
throw 'tried to use expectSubscriptions() in async test'; | ||
} | ||
return global.rxTestScheduler.expectSubscriptions.apply(global.rxTestScheduler, arguments); | ||
} | ||
|
||
export function time(marbles: string): number { | ||
if (!global.rxTestScheduler) { | ||
throw 'tried to use time() in async test'; | ||
} | ||
return global.rxTestScheduler.createTime.apply(global.rxTestScheduler, arguments); | ||
import {Observable} from '../../dist/cjs/Observable'; | ||
import {SubscriptionLog} from '../../dist/cjs/testing/SubscriptionLog'; | ||
import {ColdObservable} from '../../dist/cjs/testing/ColdObservable'; | ||
import {HotObservable} from '../../dist/cjs/testing/HotObservable'; | ||
import {TestScheduler, observableToBeFn, subscriptionLogsToBeFn} from '../../dist/cjs/testing/TestScheduler'; | ||
|
||
declare const global: any; | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. uh, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we've used it before for things like There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
export function hot<V>(marbles: string, values?: { [index: string]: V; }, error?: any): HotObservable<V>; | ||
export function hot<V>(marbles: string, values?: { [index: string]: V; } | void, error?: any): HotObservable<any> { | ||
if (!global.rxTestScheduler) { | ||
throw 'tried to use hot() in async test'; | ||
} | ||
return global.rxTestScheduler.createHotObservable.apply(global.rxTestScheduler, arguments); | ||
} | ||
|
||
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>; | ||
export function cold<V>(marbles: string, values?: { [index: string]: V; } | void, error?: any): ColdObservable<V> { | ||
if (!global.rxTestScheduler) { | ||
throw 'tried to use cold() in async test'; | ||
} | ||
return global.rxTestScheduler.createColdObservable.apply(global.rxTestScheduler, arguments); | ||
} | ||
|
||
export function expectObservable(observable: Observable<any>, | ||
unsubscriptionMarbles: string = null): ({ toBe: observableToBeFn }) { | ||
if (!global.rxTestScheduler) { | ||
throw 'tried to use expectObservable() in async test'; | ||
} | ||
return global.rxTestScheduler.expectObservable.apply(global.rxTestScheduler, arguments); | ||
} | ||
|
||
export function expectSubscriptions(actualSubscriptionLogs: SubscriptionLog[]): ({ toBe: subscriptionLogsToBeFn }) { | ||
if (!global.rxTestScheduler) { | ||
throw 'tried to use expectSubscriptions() in async test'; | ||
} | ||
return global.rxTestScheduler.expectSubscriptions.apply(global.rxTestScheduler, arguments); | ||
} | ||
|
||
export function time(marbles: string): number { | ||
if (!global.rxTestScheduler) { | ||
throw 'tried to use time() in async test'; | ||
} | ||
return global.rxTestScheduler.createTime.apply(global.rxTestScheduler, arguments); | ||
} |
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
andcold
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
andcold
.The first overload, defaults the returned
HotObservable
to be a type of string (ieColdObservable<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 ofhot('a---b---c---|', values)
will thenHotObservable<number>
;Given a more complex case (stolen from
mergeAll-spec.ts
)Given that
x
,y
, andz
are allColdObservable<string>
the type ofe1
then becomesHotObservable<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.