From ebfb11a71152f3bb3277e85796d78966bfc657c4 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Wed, 9 Jan 2019 12:35:52 +1000 Subject: [PATCH] chore(typings): add missing multicast signatures (#4452) * chore(typings): remove unnecessary signature * chore(typings): add missing signatures * chore(typings): fix dtslint tests Closes #4451 * test(retry): specify Subject type param --- spec-dtslint/operators/multicast-spec.ts | 18 ++++++++++-------- spec/operators/retry-spec.ts | 2 +- src/internal/operators/multicast.ts | 7 ++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/spec-dtslint/operators/multicast-spec.ts b/spec-dtslint/operators/multicast-spec.ts index 91912ea860..eb0673def7 100644 --- a/spec-dtslint/operators/multicast-spec.ts +++ b/spec-dtslint/operators/multicast-spec.ts @@ -11,25 +11,27 @@ it('should be possible to use a this with in a SubjectFactory', () => { }); it('should be possible to use a selector', () => { - const p = of(1, 2, 3).pipe(multicast(() => new Subject(), p => p)); // $ExpectType Observable - const o = of(1, 2, 3).pipe(multicast(() => new Subject(), p => of('foo'))); // $ExpectType Observable + 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 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 - const r = of(1, 2, 3).pipe(multicast(new Subject(), p => p)); // $ExpectError }); -it('should enforce the type', () => { +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 }); - -it('should enfore the use of `this`', () => { - const o = of(1, 2, 3).pipe(multicast(function(foo: Observable) { return new Subject(); })); // $ExpectError -}); diff --git a/spec/operators/retry-spec.ts b/spec/operators/retry-spec.ts index 39e7604ff8..87c640c9e6 100644 --- a/spec/operators/retry-spec.ts +++ b/spec/operators/retry-spec.ts @@ -199,7 +199,7 @@ describe('retry operator', () => { of(1, 2, 3).pipe( concat(throwError('bad!')), - multicast(() => new Subject()), + multicast(() => new Subject()), refCount(), retry(4) ).subscribe( diff --git a/src/internal/operators/multicast.ts b/src/internal/operators/multicast.ts index 9bd64aa499..c79b4e8795 100644 --- a/src/internal/operators/multicast.ts +++ b/src/internal/operators/multicast.ts @@ -3,13 +3,14 @@ import { Operator } from '../Operator'; import { Subscriber } from '../Subscriber'; import { Observable } from '../Observable'; import { ConnectableObservable, connectableObservableDescriptor } from '../observable/ConnectableObservable'; -import { FactoryOrValue, MonoTypeOperatorFunction, OperatorFunction, UnaryFunction } from '../types'; +import { MonoTypeOperatorFunction, OperatorFunction, UnaryFunction } from '../types'; /* tslint:disable:max-line-length */ -export function multicast(subjectOrSubjectFactory: FactoryOrValue>): UnaryFunction, ConnectableObservable>; +export function multicast(subject: Subject): UnaryFunction, ConnectableObservable>; +export function multicast(subject: Subject, selector?: MonoTypeOperatorFunction): MonoTypeOperatorFunction; +export function multicast(subject: Subject, selector?: OperatorFunction): OperatorFunction; export function multicast(SubjectFactory: (this: Observable) => Subject): UnaryFunction, ConnectableObservable>; export function multicast(SubjectFactory: (this: Observable) => Subject, selector?: MonoTypeOperatorFunction): MonoTypeOperatorFunction; -export function multicast(SubjectFactory: (this: Observable) => Subject): UnaryFunction, ConnectableObservable>; export function multicast(SubjectFactory: (this: Observable) => Subject, selector?: OperatorFunction): OperatorFunction; /* tslint:enable:max-line-length */