Skip to content

Commit

Permalink
fix: resolve issue where Subject constructor errantly allowed an argu…
Browse files Browse the repository at this point in the history
…ment (#5476)
  • Loading branch information
benlesh authored Jun 15, 2020
1 parent b280c87 commit e1d35dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions spec-dtslint/Subject-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ describe('Subject', () => {
});
});

it('should not accept an argument in the ctor', () => {
const s1 = new Subject<number>(subscriber => { }); // $ExpectError
});

describe('asObservable', () => {
it('should return an observable of the same generic type', () => {
const s1 = new Subject();
Expand Down
11 changes: 8 additions & 3 deletions src/internal/Subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export class SubjectSubscriber<T> extends Subscriber<T> {
*
* Every Subject is an Observable and an Observer. You can subscribe to a
* Subject, and you can call next to feed values as well as error and complete.
*
* @class Subject<T>
*/
export class Subject<T> extends Observable<T> implements SubscriptionLike {

Expand All @@ -42,13 +40,20 @@ export class Subject<T> extends Observable<T> implements SubscriptionLike {
thrownError: any = null;

/**
* Creates a "subject" by basically gluing an observer to an observable.
*
* @nocollapse
* @deprecated use new Subject() instead
* @deprecated Recommended you do not use, will be removed at some point in the future. Plans for replacement still under discussion.
*/
static create: Function = <T>(destination: Observer<T>, source: Observable<T>): AnonymousSubject<T> => {
return new AnonymousSubject<T>(destination, source);
}

constructor() {
// NOTE: This must be here to obscure Observable's constructor.
super();
}

lift<R>(operator: Operator<T, R>): Observable<R> {
const subject = new AnonymousSubject(this, this);
subject.operator = <any>operator;
Expand Down

0 comments on commit e1d35dc

Please sign in to comment.