throw error inside rxjs Observable : <p>I'm trying to throw an error inside a rxjs Observable</p>

<pre><code> new Observable(subscriber =&gt; {
   Observable.throw("error1");
   return Observable.throw("error2");
 })
 .subscribe(
   () =&gt; {},
   err =&gt; console.error(err)
 );
</code></pre>

<p>error 1 is not caught.</p>

<p>error2 gives a compilation error:</p>

<pre><code>Argument of type '(this: Observable&lt;{}&gt;, subscriber: Subscriber&lt;{}&gt;) =&gt; ErrorObservable&lt;string&gt;' is not assignable to parameter of type '(this: Observable&lt;{}&gt;, subscriber: Subscriber&lt;{}&gt;) =&gt; TeardownLogic'. Type 'ErrorObservable&lt;string&gt;' is not assignable to type 'TeardownLogic'
</code></pre>

<p>what is the proper way to throw an error inside an observable?</p>
