Skip to content

Commit

Permalink
chore(typings): add missing multicast signatures (#4452)
Browse files Browse the repository at this point in the history
* chore(typings): remove unnecessary signature

* chore(typings): add missing signatures

* chore(typings): fix dtslint tests

Closes #4451

* test(retry): specify Subject type param
  • Loading branch information
cartant authored and benlesh committed Jan 9, 2019
1 parent 9e90db1 commit ebfb11a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
18 changes: 10 additions & 8 deletions spec-dtslint/operators/multicast-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>(), p => p)); // $ExpectType Observable<number>
const o = of(1, 2, 3).pipe(multicast(() => new Subject<number>(), p => of('foo'))); // $ExpectType Observable<string>
const o = of(1, 2, 3).pipe(multicast(new Subject<number>(), p => p)); // $ExpectType Observable<number>
const p = of(1, 2, 3).pipe(multicast(new Subject<number>(), p => of('foo'))); // $ExpectType Observable<string>
const q = of(1, 2, 3).pipe(multicast(() => new Subject<number>(), p => p)); // $ExpectType Observable<number>
const r = of(1, 2, 3).pipe(multicast(() => new Subject<number>(), p => of('foo'))); // $ExpectType Observable<string>
});

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<string>())); // $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<string>())); // $ExpectError
const r = of(1, 2, 3).pipe(multicast(new Subject<number>(), p => p)); // $ExpectError
});

it('should enforce the type', () => {
it('should enforce the selector type', () => {
const o = of(1, 2, 3).pipe(multicast(() => new Subject<number>(), 5)); // $ExpectError
const p = of(1, 2, 3).pipe(multicast(() => new Subject<number>(), (p: string) => 5)); // $ExpectError
});

it('should enfore the use of `this`', () => {
const o = of(1, 2, 3).pipe(multicast(function(foo: Observable<number>) { return new Subject<number>(); })); // $ExpectError
});
2 changes: 1 addition & 1 deletion spec/operators/retry-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('retry operator', () => {

of(1, 2, 3).pipe(
concat(throwError('bad!')),
multicast(() => new Subject()),
multicast(() => new Subject<number>()),
refCount(),
retry(4)
).subscribe(
Expand Down
7 changes: 4 additions & 3 deletions src/internal/operators/multicast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(subjectOrSubjectFactory: FactoryOrValue<Subject<T>>): UnaryFunction<Observable<T>, ConnectableObservable<T>>;
export function multicast<T>(subject: Subject<T>): UnaryFunction<Observable<T>, ConnectableObservable<T>>;
export function multicast<T>(subject: Subject<T>, selector?: MonoTypeOperatorFunction<T>): MonoTypeOperatorFunction<T>;
export function multicast<T, R>(subject: Subject<T>, selector?: OperatorFunction<T, R>): OperatorFunction<T, R>;
export function multicast<T>(SubjectFactory: (this: Observable<T>) => Subject<T>): UnaryFunction<Observable<T>, ConnectableObservable<T>>;
export function multicast<T>(SubjectFactory: (this: Observable<T>) => Subject<T>, selector?: MonoTypeOperatorFunction<T>): MonoTypeOperatorFunction<T>;
export function multicast<T, R>(SubjectFactory: (this: Observable<T>) => Subject<T>): UnaryFunction<Observable<T>, ConnectableObservable<R>>;
export function multicast<T, R>(SubjectFactory: (this: Observable<T>) => Subject<T>, selector?: OperatorFunction<T, R>): OperatorFunction<T, R>;
/* tslint:enable:max-line-length */

Expand Down

0 comments on commit ebfb11a

Please sign in to comment.