I want to export rxjs Subject with some pre-defined behavior (via pipe()).
e.g. I want to export a subject that do console.log on each new value:
export const subj$ = new Subject()
.pipe(
tap(() => console.log('updated')
)
This works, and I'm able to subscribe() to subj$.
The problem is that this way it's impossible to do subj$.next('foo').
Of course I can export two variables for subscribe() and for next(), but that's supper silly
Actually you cannot do this. Because pipe converts Subject to Observable and this record is similar to this: new Subject().asObservable().
But, you can create your own Subject, for example from source (https://github.com/ReactiveX/rxjs/blob/master/src/internal/BehaviorSubject.ts). And make any function to invoke inside.