'Why the subscribe is not a function?

Could you fix my custom rxjs-operator, please?

As you see i created custom operator that just add some string to each element of sequence. However this operator is not working. I see the following error message in the console:

Error: obs$.pipe(...).subscribe is not a function

Here is a DEMO.

Here is a code:

import { of, Observable } from 'rxjs';
import { map } from 'rxjs/operators';

function custom() {
  return (src) => {
    return new Observable((sub) => {
      return src.subscribe({
        next(value) {
          sub.next(value + '_extra');
        },
      });
    });
  };
}

const obs$ = of(1, 2, 3, 4, 5);

obs$
  .pipe(
    map((x) => x + '___addition'),
    custom
  )
  .subscribe(console.log);


Solution 1:[1]

I forget to use parenthesis for custom-operator evoke. Correct variant is:

obs$
  .pipe(
    map((x) => x + '___addition'),
    custom()
  )
  .subscribe(console.log);

Thanks to @Andres2142

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sergey kalinin