Running a TypeScript program in Visual Studio Code | VS Code Tutorial for Beginners

Опубликовано: 16 Март 2025
на канале: Cool IT Help
5,680
59

Hello Friends,
In this tutorial session, we will learn to set up a Typescript programming environment in visual studio code. Also, we will learn to create and compile the first typescript program in visual studio code and we will learn to set up the 'tsconfig.json' file to generate all compiled files in a given folder.
Here are the steps:
In the following steps, we will learn to set up Visual Studio Code to run TypeScript program.
Note: Node.js must be installed.

Step 1: Very first we need TypeScript Compiler.
The easy way to install TypeScript is through npm, the Node.js Package Manager.
If you have npm installed, you can install TypeScript globally (-g) on your computer by:
npm install -g typescript
After installation run the below command check installation is successful or not.
tsc --version

Step 2: Creating the first TypeScript program in Visual Studio Code.
Please follow my instructions in video tutorial.
sample code :
let message: string = 'Hello World';
console.log(message);

Step 3: Set build output directory for generated .js file by creating 'tsconfig.json' file.
Add a simple tsconfig.json which set the options to compile to ES5 and use CommonJS modules.
use command : tsc.cmd --init

{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "out"
}
}
Step 4: Compiling and running .ts file.
open terminal and type : tsc.cmd filename (This will compile and create a new helloworld.js JavaScript file.)
now type : node filename.js
Step 5: Hit the like button and you can subscribe to support us and learn more.

If you found this video tutorial useful and would like to support me, you can do so by buying me a coffee using the below link!
https://buymeacoffee.com/CoolITHelp

#TypeScriptTutorialVSCode #TypeScript #CoolITHelp