Problem I face :-I am a beginner idk how to run a typescript file

in #beginnerlast month

Hi Everyone, I found two ways to run a typescript file

The solution that I found out after facing an issue after switching from javascript to Typescript:-

FirstWay:-

  1. Make a file with the extension .ts like you make js file name.js same as name.ts
  2. if you want to run just use this in the terminal like =>> this command =>(tsc filename.ts)
  3. It will automatically generate a new file with the converted code of typescript into javascript like new.ts=>new.js
  4. then run your file as always you run like (node new.js) if you are using vs code
  5. This is a very long process so try the Second way it is easy as I m a beginner I face this issue so I thought to share this problem

Second Way:-

  1. first install :-npm i typescript --save-dev
  2. initialize npx tsc --init
  3. make a file using a .ts extension like filename.ts
  4. Run this command in the terminal:- npx ts-node filename.ts