Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(dtslint): change scan operator dtslint test to reduce-like (#4093)
- Loading branch information
Showing
1 changed file
with
8 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<number> | ||
it('should infer correctly ', () => { | ||
const a = of(1, 2, 3).pipe(scan((x, y, z) => x + 1)); // $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 for accumulator of type array', () => { | ||
const a = of(1, 2, 3).pipe(scan((x: number[], y: number, i: number) => x, [])); // $ExpectType Observable<number[]> | ||
}); | ||
|
||
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> | ||
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<number> | ||
const b = of(1, 2, 3).pipe(scan((x, y, z) => x + 1, '5')); // $ExpectError | ||
}); |