Reputation: 802
I have not a project, just starting to learn typescript, so I have just one file main.ts with this code:
enum MiColor {Red=0, Green=1, Blue=2};
console.log(MiColor);
let backgroundColor = MiColor.Green;
there is not exists a compilation error, but when I try to run the code in my terminal
node main.ts
I got this error. so, why I have a runtime error as node not recognize typescript?
enum MiColor {Red=0, Green=1, Blue=2};
^^^^
SyntaxError: Unexpected reserved word
←[90m at wrapSafe (internal/modules/cjs/loader.js:1047:16)←[39m
←[90m at Module._compile (internal/modules/cjs/loader.js:1097:27)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:977:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:877:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)←[39m
←[90m at internal/main/run_main_module.js:18:47←[39m
node.js version: 12.16.3
typescript Version: 4.0.2
Upvotes: 6
Views: 10647
Reputation: 1495
Even though your file is .ts you are running as if it was JavaScript.
Install ts-node and run from it npm i -g ts-node
, then you run your project with ts-node main.ts
Upvotes: 13