diff --git a/spec-dtslint/operators/scan-spec.ts b/spec-dtslint/operators/scan-spec.ts new file mode 100644 index 00000000000..b41d7ae039c --- /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 +});