Node命令无法识别打字稿类型注释“:”

时间:2018-08-19 05:10:20

标签: node.js typescript

我是Angular的新手。我编写了以下代码来练习打字稿。

class Point
{
    x: number;
    y: number;


    constructor(a : number, b: number)
    {
        this.x = a;
        this.y = b;
    }


    draw()
    {
        console.log("X = "+this.x+"and Y = "+this.y)
    }

}

let point = new Point(1,2);
point.draw();

此代码已成功编译。但是,当我尝试使用node main.ts命令运行它时,出现了以下错误。

C:\Users\Tim\Desktop\hello\main.ts:3
    x: number;
     ^

SyntaxError: Unexpected token :
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

请问有人可以指出这段代码有什么问题吗?

0 个答案:

没有答案