diff --git a/spec-dtslint/Subject-spec.ts b/spec-dtslint/Subject-spec.ts index 1c21d8c84b..85ef36d5fe 100644 --- a/spec-dtslint/Subject-spec.ts +++ b/spec-dtslint/Subject-spec.ts @@ -30,6 +30,10 @@ describe('Subject', () => { }); }); + it('should not accept an argument in the ctor', () => { + const s1 = new Subject(subscriber => { }); // $ExpectError + }); + describe('asObservable', () => { it('should return an observable of the same generic type', () => { const s1 = new Subject(); diff --git a/src/internal/Subject.ts b/src/internal/Subject.ts index 32399bd0e8..1d535a08da 100644 --- a/src/internal/Subject.ts +++ b/src/internal/Subject.ts @@ -22,8 +22,6 @@ export class SubjectSubscriber extends Subscriber { * * 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 */ export class Subject extends Observable implements SubscriptionLike { @@ -42,13 +40,20 @@ export class Subject extends Observable 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 = (destination: Observer, source: Observable): AnonymousSubject => { return new AnonymousSubject(destination, source); } + constructor() { + // NOTE: This must be here to obscure Observable's constructor. + super(); + } + lift(operator: Operator): Observable { const subject = new AnonymousSubject(this, this); subject.operator = operator;