TypeScript execution with inconsistent order

Viewed 693

I am experiencing some issues on TypeScript 2.4.1, Node.js v8.1.3, and VS Code 1.14.0.

For some reason, my experimental code does not print in order. Especially rest and foreach section.

Here is my test page.

Am I missing something here?

GggDataStructuresIntTests.ts

var dotdotdotFun = function () {
    let [first, ...rest] = [1, 2, 3, 4, 5];
    console.log("first", first); // outputs 1
    console.log("rest", rest); // outputs [ 2, 3, 4 ]
    rest.forEach((item) => {
        console.log("forEach", item);
    });
}
dotdotdotFun();

tsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "outDir": "js/",
        "sourceMap": true,
        "lib": [ "es2015" ],        
        "watch": true
    },
    "exclude": [
        "node_modules",
        "typings/browser.d.ts",
        "typings/browser"
    ]
}

launch.json

{

    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Node.js",            
            "program": "${file}",
            "outFiles": [
                "${workspaceRoot}/js/**/*.js"
            ]
        }        
    ]
}

There is some outputs;

Output 1:

enter image description here

Output 2:

enter image description here

Output 3:

enter image description here

1 Answers
Related