Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions spec/operators/scan-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,19 @@ describe('Observable.prototype.scan', () => {
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should accept array typed reducers', () => {
it('should accept array types', () => {
type(() => {
let a: Rx.Observable<{ a: number; b: string }>;
a.reduce((acc, value) => acc.concat(value), []);
a.scan((acc, value) => acc.concat(value), []);
});
});

it('should accept T typed reducers', () => {
it('should accept T types', () => {
type(() => {
let a: Rx.Observable<{ a?: number; b?: string }>;
a.reduce((acc, value) => {
value.a = acc.a;
value.b = acc.b;
a.scan((acc, value) => {
acc.a = value.a;
acc.b = value.b;
return acc;
}, {});
});
Expand All @@ -249,9 +249,9 @@ describe('Observable.prototype.scan', () => {
it('should accept R typed reducers', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test dosen't seem right. Shouldn't the actual call to .scan be something like this?

a.scan<{ a: number, b: string }, { a?: number; b?: string }>((acc, value) => { ...

Copy link
Member

Choose a reason for hiding this comment

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

isn't it for T only overload testing?

scan<T>(this: Observable<T>, accumulator: (acc: T, value: T, index: number) => T, seed?: T)

Copy link
Contributor Author

@hsubra89 hsubra89 Oct 4, 2017

Choose a reason for hiding this comment

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

@kwonoj Well, the test is called should accept R typed reducers. I'm assumed that meant we're explicitly testing the case where we have two different types for acc and the source. I'm guessing that based on the other tests in the file, i.e, there's another one for T typed reducers and `Array typed reducers'

Copy link
Member

Choose a reason for hiding this comment

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

I think we can't just trust test name and test cases here at all, since from first it was testing reduce anyway 😅 I was just guessing by usage of code here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because of the way the overloads and the tests are set-up, in the actual test, both acc and value are T. Which means acc isn't really inheriting what R is supposed to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should leave this as-is for now, and i'll propose some changes to these tests in #2897 after we get this in ?

type(() => {
let a: Rx.Observable<{ a: number; b: string }>;
a.reduce<{ a?: number; b?: string }>((acc, value) => {
value.a = acc.a;
value.b = acc.b;
a.scan<{ a?: number; b?: string }>((acc, value) => {
acc.a = value.a;
acc.b = value.b;
return acc;
}, {});
});
Expand Down