Topic: Installing TypeScript and Running it in VS Code

  1. 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
  2. Create a folder on your computer and inside it, create a file named app.ts.

  3. In the terminal, run:

    tsc app.ts

    This will generate an app.js file in the same folder.

  4. 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:

  1. ESLint: Provides linting for TypeScript to catch errors and improve code quality.

  2. Prettier: Automatically formats your code for consistency and readability.

  3. Debugger for Chrome: Allows you to debug TypeScript code directly in the browser from VS Code.