title: Writing a custom ngrx operator and returning the source observable type
body: <p>I have a custom operator, <code>waitFor</code> which I am using in my effects as so:</p>
  <pre><code>public effect$: Observable&lt;Action&gt; = createEffect(() =&gt; {
      return this.actions$.pipe(
        ofType(myAction),
        waitFor&lt;ReturnType&lt;typeof myAction&gt;&gt;([anotherAction]),
        ...etc
      );
    });
  </code></pre>
  <p>It basically looks at correlationId's to not continue executing until the array of actions have been dispatched. But that is beside the point here.</p>
  <p>As expected <code>ofType</code> takes the source observable and uses this as the return type, however I am struggling to achieve the same effect. As you can see above I am using <code>ReturnType&lt;typeof myAction&gt;&gt;</code> and the following in my <code>waitFor</code> method:</p>
  <pre><code>export function waitFor&lt;A extends Action&gt;(actionsToWaitFor$: Array&lt;Actions&gt;): OperatorFunction&lt;A, A&gt; {
  </code></pre>
  <p>So at the moment if I call <code>waitFor</code> like this:</p>
  <pre><code>public effect$: Observable&lt;Action&gt; = createEffect(() =&gt; {
      return this.actions$.pipe(
        ofType(myAction),
        waitFor([anotherAction]),
        ...etc
      );
    });
  </code></pre>
  <p>Then its type is inferred as <code>Action</code>, but I want this to be <code>ReturnType&lt;typeof theSourceObservable&gt;</code> by default. So I would assume I would need something like this in my <code>waitFor</code> method:</p>
  <pre><code>export function waitFor&lt;A extends ReturnType&lt;typeof sourceObservable?!&gt;&gt;(actionsToWaitFor$: Array&lt;Actions&gt;): OperatorFunction&lt;A, A&gt; {
  </code></pre>
  <p><code>waitFor</code> looks like this:</p>
  <pre><code>export function waitFor&lt;A extends Action&gt;(actionsToWaitFor$: Array&lt;Actions&gt;): OperatorFunction&lt;A, A&gt; {
    return (source$) =&gt; {
      return source$.pipe(
        switchMap((action: A &amp; { correlationId: string}) =&gt; {
          // use zip() to wait for all actions 
          // and when omitting map((action) =&gt; action)
          // so the original action is always returned
        })
      );
    };
  }
  </code></pre>
  <p>From the <code>ofType</code> <a href="https://github.com/ngrx/platform/blob/master/modules/effects/src/actions.ts#L63" rel="noreferrer">source</a>, it looks like I need to use <code>Extract</code></p>
  <h2>Update</h2>
  <p>StackBlitz example is shown <a href="https://stackblitz.com/edit/angular-ivy-6ujmnw?file=src%2Fapp%2Fexample.service.ts" rel="noreferrer">here</a></p>