title: Angular - returning value from inside 'then'
body: <p>I've looked at similar questions on StackOverflow but none of them match my specific problem:</p>
  
  <p>I have a TypeScript function in an Angular 6 service, calling a function in another service like this:</p>
  
  <p><strong>Service1:</strong></p>
  
  <pre><code>myArray: Array&lt;IMyInterface&gt;
  
  ...
  
  getArray(): Observable&lt;IMyInterface[]&gt; {
  
      this.myArray= this.service2.getAnArray(1);
      return Observable.of(this.myArray);
  }
  </code></pre>
  
  <p><strong>Service2</strong></p>
  
  <pre><code>getAnArray(myEntityId): Array&lt;IMyInterface&gt; {
    const myArray2: IMyInterface[] = [];
  
    this.getConnection().then(connection =&gt; {
      connection.invoke('GetEntityById', myEntityId).then((someJson: any) =&gt; {
        someJson.forEach( x =&gt; myArray2.push(x));       
        return myArray2;
      })
    }); 
  }
  </code></pre>
  
  <p>It gives me the error in Service2 <code>A function whose declared type is neither 'void' nor 'any' must return a value.</code></p>
  
  <p>I need to return <code>myArray2</code> <em>after</em> <code>connection.invoke('GetEntityById', myId)</code> has resolved, as the array is only populated after that resolves, which is why I try to do it inside <code>then</code>.</p>
  
  <p>How do I do this?</p>