diff --git a/api_guard/dist/types/operators/index.d.ts b/api_guard/dist/types/operators/index.d.ts index 4df5ca75dbd..b973c8cface 100644 --- a/api_guard/dist/types/operators/index.d.ts +++ b/api_guard/dist/types/operators/index.d.ts @@ -1,5 +1,3 @@ -import { ObservableInput } from ".."; - export declare function audit(durationSelector: (value: T) => ObservableInput): MonoTypeOperatorFunction; export declare function auditTime(duration: number, scheduler?: SchedulerLike): MonoTypeOperatorFunction; @@ -241,7 +239,7 @@ export declare function retry(config: RetryConfig): MonoTypeOperatorFunction< export interface RetryConfig { count?: number; delay?: number | ((error: any, retryCount: number) => ObservableInput); - resetOnSuccess?: boolean; b + resetOnSuccess?: boolean; } export declare function retryWhen(notifier: (errors: Observable) => Observable): MonoTypeOperatorFunction; diff --git a/spec-dtslint/operators/sample-spec.ts b/spec-dtslint/operators/sample-spec.ts index 48b011f0b9a..647e00a88e9 100644 --- a/spec-dtslint/operators/sample-spec.ts +++ b/spec-dtslint/operators/sample-spec.ts @@ -1,11 +1,77 @@ import { of } from 'rxjs'; import { sample } from 'rxjs/operators'; +import { asInteropObservable } from '../../spec/helpers/interop-helper'; it('should enforce parameter', () => { - const a = of(1, 2, 3).pipe(sample()); // $ExpectError + of(1, 2, 3).pipe(sample()); // $ExpectError }); it('should accept observable as notifier parameter', () => { - const a = of(1, 2, 3).pipe(sample(of(4))); // $ExpectType Observable - const b = of(1, 2, 3).pipe(sample(of('a'))); // $ExpectType Observable + of(1, 2, 3).pipe(sample(of(4))); // $ExpectType Observable + of(1, 2, 3).pipe(sample(of('a'))); // $ExpectType Observable +}); + +it('should accept interop observable notifier', () => { + of(1, 2, 3).pipe(sample(asInteropObservable(of(true)))); // $ExpectType Observable +}); + +it('should accept promise notifier', () => { + of(1, 2, 3).pipe(sample(Promise.resolve(true))); // $ExpectType Observable +}); + +it('should async iterable notifier', () => { + const asyncRange = { + from: 1, + to: 2, + [Symbol.asyncIterator]() { + return { + current: this.from, + last: this.to, + async next() { + await Promise.resolve(); + const done = (this.current > this.last); + return { + done, + value: done ? this.current++ : undefined + }; + } + }; + } + }; + of(1, 2, 3).pipe(sample(asyncRange)); // $ExpectType Observable +}); + +it('should accept iterable notifier', () => { + const syncRange = { + from: 1, + to: 2, + [Symbol.iterator]() { + return { + current: this.from, + last: this.to, + next() { + const done = (this.current > this.last); + return { + done, + value: done ? this.current++ : undefined + }; + } + }; + } + }; + of(1, 2, 3).pipe(sample(syncRange)); // $ExpectType Observable +}); + +it('should accept readable stream notifier', () => { + const readableStream = new ReadableStream({ + pull(controller) { + controller.enqueue('x'); + controller.close(); + }, + }); + of(1, 2, 3).pipe(sample(readableStream)); // $ExpectType Observable +}); + +it('should enforce types of the notifier', () => { + of(1, 2, 3).pipe(sample(8)); // $ExpectError });