Skip to content

Commit

Permalink
test(dtslint): add dtslint test for scan operator (#4093)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkosasih committed Nov 17, 2018
1 parent de9d2e4 commit c5c2336
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 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<number>
});

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<number>
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<number[]>
});

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<string>
});

0 comments on commit c5c2336

Please sign in to comment.