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

fix: resolve issue where Subject constructor errantly allowed an argu… #5476

Merged
merged 1 commit into from Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec-dtslint/Subject-spec.ts
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
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