Error 'takeUntil is not a function' on all my Observables

WillyC picture WillyC · Apr 20, 2017 · Viewed 7.7k times · Source

For some reason I can't use the takeUntil method on any of my observables.

My IDE (Visual Studio Code) shows it as a valid method while I'm coding, and it compiles fine (from typescript), but when I run it I get takeUntil is not a function on any of my observables.

I'm using rxjs version 5.3.0.

I can make it happen in a wide variety of ways, but this is likely the most straightforward:

let subject:BehaviorSubject<any> = new BehaviorSubject<any>({});
let unsubscribe: Subject<void> = new Subject<void>();
subject.takeUntil(unsubscribe);

Honestly I can't find any way to instantiate anything where takeUntil doesn't result in that error, but the IDE never complains and typescript always compiles fine - the error always occurs in the browser.

Answer

JusMalcolm picture JusMalcolm · Apr 20, 2017

you probably need to import the takeUntil operator:

import 'rxjs/add/operator/takeUntil';