1

I appreciate that this is likely a naive question, however I am trying to find my way in the dark and the documentation from Microsoft really isn't as intuitive as I need it to be, since I've never worked with either Visual Studio Code or TypeScript before.

I have written and saved a basic .ts file:

// my-first-typescript.ts

const myConst: number = 22;
console.log(myConst / 2);

If I now run Visual Studio Code > Terminal > New Terminal and I enter:

tsc my-first-typescript.ts

a console pops up on Windows 7 asking:

Choose the program you want to use to open this file

Obviously the Terminal is trying to open tsc.js and it doesn't know how.

This is where I'm stuck.

Is there any way to execute tsc.js without having Node.js installed? (I'm guessing not?)

But then, hasn't Visual Studio Code already installed itself with Node.js? (If not, what's the Node.js 12.14.1 it refers to?)

I'm trying as much as possible to avoid downloading and installing Node.js and npm.

If I absolutely have to, then I will.

But it's a lot to download just to be able to run the TypeScript Compiler (tsc) in Visual Studio Code.

Rounin
  • 27,134
  • 9
  • 83
  • 108

1 Answers1

1

You have to install typescript into your environment. And yes you need node installed.

After install node/npm you can install typescript with

npm install -g typescript

After that you can call the compiler tsc, That will just convert the file from .ts to .js

If you want to run it, I recommend to install ts-node

then you can do

ts-node myFile.ts
distante
  • 6,438
  • 6
  • 48
  • 90
  • Thank you, @distante. So what's the reference in `Visual Studio Code > Help > About` to **Node.js 12.14.1**? Is it saying that's the version of `Node.js` it already recognises on my computer? Or is it saying that's the (optimal) version of `Node.js` it needs? – Rounin Nov 20 '20 at 09:14
  • 1
    @Rounin to be honest I am not 100% sure. But I think it refers to the internal node compilation that VsSode uses (it is an javascript/electron/node App). Because I have node 12.13 installed but I also get 12.14.1 in VsCode. – distante Nov 20 '20 at 09:30
  • Thanks for that clarification, @distante. That suggests that whatever VSCode is referring to, it isn't related to any version of `node` already installed locally. – Rounin Nov 20 '20 at 09:33
  • 1
    @Rounin Help -> About shows the internal Node.js version used by VS Code, which is an Electron app. Electron comes bundled with its own node version. – bela53 Nov 20 '20 at 09:39
  • Many thanks, again, @distante - I finally got there. And, believe it or not, the single most important sentence for me in your answer was: _"And yes you need node installed."_ because I spent hours yesterday, trying to get Visual Studio Code & TypeScript running while avoiding at all costs installing `node.js` and `npm`. – Rounin Nov 20 '20 at 17:54
  • 1
    No problem @Rounin we all are beginners with some technology, library or API :D – distante Nov 20 '20 at 18:31