Ahoy there! Let's set up the environment for playing with TypeScript and learn how to run those TypeScript files!
Step 0: Install TypeScript
First let's install TypeScript globally if you don't have it yet.
npm i -g typescript
(By the way, "npm i X" is the short-hand for "npm install X")
Now, let's create your project folder and open it in your beloved editor (mine VS Code)
Step 1: init tsconfig
Let's init the tsconfig file, type the following command
tsc --init
(This "tsc" command will only work if you have typescript globally installed)
It'll create a "tsconfig.json" file. Now, what does it do you ask? TypeScript is the superset of JavaScript and how we want to compile it will be defined by this tsconfig file. The best part is, it'll give you linting (the red lines whenever there is an error in your code or logic) and also explicitly tell you what mistakes you are doing and in some cases possible solutions as well. Amazing right?
Step 2: run TypeScript files
Now you created a TypeScript file, wrote your code, for example an app.ts file with this content
console.log('Hello there TypeScript! You are AMAIZING!!')
Now how to run this file? If it were a JavaScript file, like app.js, you might run "node app.js" or "nodemon app.js", right? So let's find the TypeScript versions for those!
Let's install the packages
npm i ts-node ts-node-dev
"ts-node" is the TypeScript version for "node" and "ts-node-dev" is the TypeScript version for "nodemon". So to run the TypeScript file use either of these commands
ts-node app.ts
(Which is basically "node app.js")
ts-node-dev app.ts
(Which is basically "nodemon app.js")
YIPPIE!! You just set up the environment for coding in TypeScript and also learnt how to run those FILES!! YOOOHOOOO!!! But now what?
What's NEXT?
1. Improved AI BOT that can do anything
2. Insane stuff with JavaScript/TypeScript
3. Debugging TypeScript with VS Code Debugger
4. How to automate anything
5. Sequelize Hooks
6. Automate creating DB Schemas
7. How to create an Android APP with NO XP
(including apk generating)
Got any doubt?
Drop a comment or Feel free to reach out to me @SilveLEAF on Twitter or Linkedin
Wanna know more about me? Come here!
SilvenLEAF.github.io
Top comments (0)