import { of, Subject, Observable } from 'rxjs'; import { multicast } from 'rxjs/operators'; it('should infer correctly', () => { const o = of(1, 2, 3).pipe(multicast(new Subject())); // $ExpectType Observable const p = of(1, 2, 3).pipe(multicast(() => new Subject())); // $ExpectType Observable }); it('should be possible to use a this with in a SubjectFactory', () => { const o = of(1, 2, 3).pipe(multicast(function(this: Observable) { return new Subject(); })); // $ExpectType Observable }); it('should be possible to use a selector', () => { const o = of(1, 2, 3).pipe(multicast(new Subject(), p => p)); // $ExpectType Observable const p = of(1, 2, 3).pipe(multicast(new Subject(), p => of('foo'))); // $ExpectType Observable const q = of(1, 2, 3).pipe(multicast(() => new Subject(), p => p)); // $ExpectType Observable const r = of(1, 2, 3).pipe(multicast(() => new Subject(), p => of('foo'))); // $ExpectType Observable }); it('should support union types', () => { const o = of(1, 2, 3).pipe(multicast(new Subject(), p => Math.random() > 0.5 ? of(123) : of('foo'))); // $ExpectType Observable const p = of(1, 2, 3).pipe(multicast(() => new Subject(), p => Math.random() > 0.5 ? of(123) : of('foo'))); // $ExpectType Observable }); it('should enforce types', () => { const p = of(1, 2, 3).pipe(multicast()); // $ExpectError }); it('should enforce Subject type', () => { const o = of(1, 2, 3).pipe(multicast('foo')); // $ExpectError const p = of(1, 2, 3).pipe(multicast(new Subject())); // $ExpectError }); it('should enforce SubjectFactory type', () => { const p = of(1, 2, 3).pipe(multicast('foo')); // $ExpectError const q = of(1, 2, 3).pipe(multicast(() => new Subject())); // $ExpectError }); it('should enforce the selector type', () => { const o = of(1, 2, 3).pipe(multicast(() => new Subject(), 5)); // $ExpectError const p = of(1, 2, 3).pipe(multicast(() => new Subject(), (p: string) => 5)); // $ExpectError });