2

I am a newbie to Angular. I wrote the following code to practice typescript.

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();

This code compiled successfully. But when I tried to run it using the node main.ts command it gave the following error.

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

Can anyone point me out what's wrong with this code, please?

Pegasus008
  • 561
  • 6
  • 17
  • try with `node main.js` . The typescript file should be already compiled to js file. so you should be using the js file. – Niladri Aug 19 '18 at 06:08

0 Answers0