Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stricter type definition of Subject #5307

Merged
merged 3 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions spec/Subject-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe('Subject', () => {
});

it('should not allow values to be nexted after it is unsubscribed', (done: MochaDone) => {
const subject = new Subject();
const subject = new Subject<string>();
const expected = ['foo'];

subject.subscribe(function (x) {
Expand Down Expand Up @@ -397,7 +397,7 @@ describe('Subject', () => {

it('should be an Observer which can be given to Observable.subscribe', (done: MochaDone) => {
const source = of(1, 2, 3, 4, 5);
const subject = new Subject();
const subject = new Subject<number>();
const expected = [1, 2, 3, 4, 5];

subject.subscribe(
Expand All @@ -414,7 +414,7 @@ describe('Subject', () => {

it('should be usable as an Observer of a finite delayed Observable', (done: MochaDone) => {
const source = of(1, 2, 3).pipe(delay(50));
const subject = new Subject();
const subject = new Subject<number>();

const expected = [1, 2, 3];

Expand All @@ -431,7 +431,7 @@ describe('Subject', () => {
});

it('should throw ObjectUnsubscribedError when emit after unsubscribed', () => {
const subject = new Subject();
const subject = new Subject<string>();
subject.unsubscribe();

expect(() => {
Expand Down
4 changes: 2 additions & 2 deletions spec/observables/from-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ describe('from', () => {
expect(nextInvoked).to.equal(false);
});
it(`should accept a function`, (done) => {
const subject = new Subject();
const handler: any = (...args: any[]) => subject.next(...args);
const subject = new Subject<any>();
const handler: any = (arg: any) => subject.next(arg);
handler[observable] = () => subject;
let nextInvoked = false;

Expand Down
2 changes: 1 addition & 1 deletion spec/operators/bufferCount-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('bufferCount operator', () => {
});

it('should buffer properly (issue #2062)', () => {
const item$ = new Subject();
const item$ = new Subject<number>();
const results: any[] = [];
item$.pipe(
bufferCount(3, 1)
Expand Down
2 changes: 1 addition & 1 deletion spec/operators/skipUntil-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ describe('skipUntil', () => {
const e1 = hot( '--a--b--c--d--e--|');
const e1subs = ['^ !',
'^ !']; // for the explicit subscribe some lines below
const skip = new Subject();
const skip = new Subject<string>();
const expected = '-----------------|';

e1.subscribe((x: string) => {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/Subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class SubjectSubscriber<T> extends Subscriber<T> {
*
* @class Subject<T>
*/
export class Subject<T> extends Observable<T> implements SubscriptionLike {
export class Subject<T = void> extends Observable<T> implements SubscriptionLike {

[rxSubscriberSymbol]() {
return new SubjectSubscriber(this);
Expand Down Expand Up @@ -58,7 +58,7 @@ export class Subject<T> extends Observable<T> implements SubscriptionLike {
return <any>subject;
}

next(value?: T) {
next(value: T) {
if (this.closed) {
throw new ObjectUnsubscribedError();
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/operators/repeatWhen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class RepeatWhenOperator<T> implements Operator<T, T> {
*/
class RepeatWhenSubscriber<T, R> extends OuterSubscriber<T, R> {

private notifications: Subject<any> | null = null;
private notifications: Subject<void> | null = null;
private retries: Observable<any> | null = null;
private retriesSubscription: Subscription | null | undefined = null;
private sourceIsBeingSubscribedTo: boolean = true;
Expand Down
2 changes: 1 addition & 1 deletion src/internal/operators/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Subject } from '../Subject';
import { MonoTypeOperatorFunction } from '../types';

function shareSubjectFactory() {
return new Subject();
return new Subject<any>();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/internal/operators/windowTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ interface CloseState<T> {
class CountedSubject<T> extends Subject<T> {
private _numberOfNextedValues: number = 0;

next(value?: T): void {
next(value: T): void {
this._numberOfNextedValues++;
super.next(value);
}
Expand Down