I am using Typescript to write JS promises. I have a compound promise, i.e. promise which returns a promise I have:
test() {
    addElement("first")
        .then(
            function (val){
                addElement("second");
                console.log("second*);
            })
            .then(
            function (val){
                addElement("third");
                console.log("third*");
            });
}
export function addElement(elementText){
    return new Promise(function(resolve,reject){
        setTimeout(function(){
            resolve();
        }, Math.random() * 2000);
    })
    .then(console.log(elementText));
}
I would like these functions to print out, first, second*, second, third*, third. However, I get:
JS: first JS: second* JS: third* JS: third JS: second
How do I get the then to execute after the called promises' then has completed?