How to do conditional promise chaining
<p>I'm learning promises/typescript/angular and I want to chain promises conditionally. </p>

<p>This is the actual state of my method:</p>

<pre><code>private executePromiseModificationEvenement&lt;T&gt;(edition: Models.CalendrierParametresModelEdition, modeCreation: boolean, deferred: ng.IDeferred&lt;T&gt;) {
    var promise: ng.IPromise&lt;Object&gt;;

    //Step1
    if (modeCreation) {
        promise = this.$calendrier.Actions.enregistrerEvenementOutlook(edition);
    } else {
        promise = this.$calendrier.Actions.modifierEvenementOutlook(edition);
    }

    if (this.$scope.outlook) {
        promise.then((x) =&gt; {
            if (x != '') edition.idOutlook = x.toString();;
            return deferred.resolve();
        }, (x) =&gt; {
            return deferred.reject();
        });
    } else {
        //Step2
        promise.then((x) =&gt; {
            if (x != '') edition.idOutlook = x.toString();
            return this.$calendrier.Actions.modifierEvenement(edition);
        }, (x) =&gt; {
            //Ajout MessageBox message error
            return this.$calendrier.Actions.modifierEvenement(edition);
        })
        //Step3
        .then((x) =&gt; {
            if (edition.opportunite != null) this.$rootScope.$broadcast("pushEchangeOpportunite", { idOpportunite: parseInt(edition.opportunite), action: 2, IdContact: edition.id, Libelle: edition.title, StartDate: moment(edition.start).toDate() });
            return deferred.resolve();
        }, (x) =&gt; {
            return deferred.reject();
        });
    }
}
</code></pre>

<p>I'm familiar of async/await of C#, neither of which gives a problem with conditional chaining, but I'm having trouble achieving the same with promises.</p>

<p>Is it to correct to put a <strong>.then</strong> not just after the creation of the promise but after an <strong>if</strong> ? </p>

<p>Is it possible that the <strong>.then</strong> may never be called because the promise is already finished?</p>