代码之家  ›  专栏  ›  技术社区  ›  Teoman shipahi

顺序不一致的TypeScript执行

  •  3
  • Teoman shipahi  · 技术社区  · 8 年前

    我在TypeScript 2.4.1节点上遇到一些问题。js v8.1.3和VS代码1.14.0。

    由于某种原因,我的实验代码没有按顺序打印。特别是休息和每节。

    这是我的测试页面。

    我错过什么了吗?

    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"
                ]
            }        
        ]
    }
    

    有一些输出;

    enter image description here

    输出2:

    enter image description here

    enter image description here

    1 回复  |  直到 8 年前
        1
  •  1
  •   Teoman shipahi    7 年前

    之后 Yeshan Jay v8.2.0 Documentation

    有一个声明如下:;

    安慰

    警告:全局控制台对象的方法是 两者都不一致 就像它们类似的浏览器API一样, 他们也不是 在…上 process I/O for 更多信息。

    我没有检查上一个节点引擎,但在这个新版本(>=8)上,它看起来像控制台。log()根本不应该被假设为同步的。