How to chain 3 Promises with angular2 and typescript
<p>I have successfully chained promises, but I find the way I did it enough complicated: I'm wondering if there is not a more elegant way to do it.</p>

<p>I use Angular2, Typescript and signalR.</p>

<p>I have a service <code>getIntervention</code> that returns an object from the server by Id.</p>

<p>Before calling <code>getIntervention</code>, I want to check the client to be connected to the server, and before connecting to the server, I want the SignalR scripts to be loaded.</p>

<p>So I created a first promise <code>scriptLoadedPromise</code> that waits for the SignalR script to be loaded. When <code>scriptLoadedPromise</code> is resolved a new promise <code>connectionPromise</code> is created that waits for the connection to be established.</p>

<p>When <code>connectionPromise</code>  is resolved, call the service <code>getIntervention</code>.</p>

<p>For each promise I added callbacks named <code>scriptLoaded</code>  and <code>connectionDetected</code>  that call <code>resolve()</code>.</p>

<p>Here is my code:</p>

<pre><code>public loadIntervention( numFI : number ) : Promise&lt;Intervention&gt;
{

    let scriptLoadedPromise : Promise&lt;Intervention&gt; = new Promise( ( resolve, reject ) =&gt;
    { 
        // si le script est chargé alors la promesse est déjà tenue
        if ( this.isScriptLoaded )
            resolve();
        else
            this.scriptLoaded = ( () =&gt; { resolve(); } ) ;
    }).then
    ( () =&gt; {
        let connectionPromise : Promise&lt;Intervention&gt; = new Promise( (resolve, reject) =&gt;
        {
            // si le serveur est connecté alors la promesse de connection est déjà tenue
            if ( this.Connected )
                resolve();
            else
                this.connectionDetected = ( () =&gt; { console.log("RECONNETED !!!!!"); resolve(); } );

        } )
        .then( ()  =&gt; { return this.proxy.server.getIntervention( numFI ); } );

        return connectionPromise;
    });


    return scriptLoadedPromise;
}
</code></pre>

<p>Is there a way to simplify that implementation where 3 promises are chained ?</p>