Topic: Installing TypeScript and Running it in VS Code
-
Install TypeScript globally by running the following command in your terminal:
npm install -g typescript npm install --save-dev typescript // install project only
Verify installation with:
tsc -v
-
Create a folder on your computer and inside it, create a file named
app.ts
. -
In the terminal, run:
tsc app.ts
This will generate an
app.js
file in the same folder. -
Create an
index.html
file in the same folder, and add the following code to link the generated JavaScript file:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script src="app.js"></script> </body> </html>
Now you can open index.html
in a browser to see the result.
Optional: Enhance the TypeScript workflow in VS Code with these extensions:
-
ESLint: Provides linting for TypeScript to catch errors and improve code quality.
-
Prettier: Automatically formats your code for consistency and readability.
-
Debugger for Chrome: Allows you to debug TypeScript code directly in the browser from VS Code.