From b779e6268c87fbfc51081ba6d03964c9c8ec3880 Mon Sep 17 00:00:00 2001 From: Deddy Kosasih Date: Sat, 17 Nov 2018 22:56:47 +1100 Subject: [PATCH 1/2] test(dtslint): add dtslint test for scan operator (#4093) --- spec-dtslint/operators/scan-spec.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 spec-dtslint/operators/scan-spec.ts diff --git a/spec-dtslint/operators/scan-spec.ts b/spec-dtslint/operators/scan-spec.ts new file mode 100644 index 0000000000..b41d7ae039 --- /dev/null +++ b/spec-dtslint/operators/scan-spec.ts @@ -0,0 +1,23 @@ +import { of } from 'rxjs'; +import { scan } from 'rxjs/operators'; + +it('should enforce accumulator function as parameter', () => { + const a = of(1, 2, 3).pipe(scan()); // $ExpectError +}); + +it('should infer correctly with single T value', () => { + const a = of(1, 2, 3).pipe(scan((acc, val, i) => acc + val)); // $ExpectType Observable +}); + +it('should do a type check on seed parameter', () => { + const b = of(1, 2, 3).pipe(scan((acc, val, i) => acc + val, 0)); // $ExpectType Observable + const a = of(1, 2, 3).pipe(scan((acc, val, i) => acc + val, 'y')); // $ExpectError +}); + +it('should infer correctly with Array of T value', () => { + const a = of(1, 2, 3).pipe(scan((acc: number[], val: number, i) => [...acc, val])); // $ExpectType Observable +}); + +it('should infer correctly with type change accumulator', () => { + const a = of(1, 2, 3).pipe(scan((acc: string, val: number, i) => `${acc} ' ' ${val}`)); // $ $expectType Observable +}); From 8d5551a7e50806839546bd7a8b6117c3fb8b3077 Mon Sep 17 00:00:00 2001 From: Deddy Kosasih Date: Wed, 30 Jan 2019 23:19:04 +0700 Subject: [PATCH 2/2] test(dtslint): change scan operator dtslint test to reduce-like (#4093) --- spec-dtslint/operators/scan-spec.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/spec-dtslint/operators/scan-spec.ts b/spec-dtslint/operators/scan-spec.ts index b41d7ae039..7f11324c9f 100644 --- a/spec-dtslint/operators/scan-spec.ts +++ b/spec-dtslint/operators/scan-spec.ts @@ -1,23 +1,19 @@ import { of } from 'rxjs'; import { scan } from 'rxjs/operators'; -it('should enforce accumulator function as parameter', () => { +it('should enforce parameter', () => { const a = of(1, 2, 3).pipe(scan()); // $ExpectError }); -it('should infer correctly with single T value', () => { - const a = of(1, 2, 3).pipe(scan((acc, val, i) => acc + val)); // $ExpectType Observable +it('should infer correctly ', () => { + const a = of(1, 2, 3).pipe(scan((x, y, z) => x + 1)); // $ExpectType Observable }); -it('should do a type check on seed parameter', () => { - const b = of(1, 2, 3).pipe(scan((acc, val, i) => acc + val, 0)); // $ExpectType Observable - const a = of(1, 2, 3).pipe(scan((acc, val, i) => acc + val, 'y')); // $ExpectError +it('should infer correctly for accumulator of type array', () => { + const a = of(1, 2, 3).pipe(scan((x: number[], y: number, i: number) => x, [])); // $ExpectType Observable }); -it('should infer correctly with Array of T value', () => { - const a = of(1, 2, 3).pipe(scan((acc: number[], val: number, i) => [...acc, val])); // $ExpectType Observable -}); - -it('should infer correctly with type change accumulator', () => { - const a = of(1, 2, 3).pipe(scan((acc: string, val: number, i) => `${acc} ' ' ${val}`)); // $ $expectType Observable +it('should accept seed parameter of the same type', () => { + const a = of(1, 2, 3).pipe(scan((x, y, z) => x + 1, 5)); // $ExpectType Observable + const b = of(1, 2, 3).pipe(scan((x, y, z) => x + 1, '5')); // $ExpectError });