The installation

Installation of TypeScript requires the use of NPM, a package management tool that comes with NodeJS

  1. Install NodeJS. Download NodeJS from the official website. You are advised to download the LTS version (long-term support version), download the corresponding installation package, and proceed to the next step until the installation is complete. To check whether the NPM is successfully installed, run the NPM -v command. If the version number is displayed, the installation is successful

  2. Install the TypeScriptMac terminal or Windows PowerShell enter the command npm i -g typescriptWait until the installation is complete. To verify the installation, enter the commandtscIf the version number and a message are displayed, the installation is successful.

    At this point, TypeScript is already installed.


    compile

    Typically we use.ts as the extension for TypeScript code files. Then we create a new app.ts file with the following code

    let msg = "Hello TypeScript"
    console.log(msg)
    Copy the code

    Compile TypeScript code into JavaScript code using the TSC app.ts command. At this point, an app.js file will be generated in the same directory as app.ts, with the following code

    let msg = "Hello TypeScript"
    console.log(msg)
    Copy the code

    You can execute the JS file using the command node app.js, or you can run the JS file using the IDE

    The TypeScript editor

    Use Visual Studio Code or WebStorm, which supports both Windows and Mac. The former is developed by Microsoft and is free and open source. The latter is developed by JetBrains for a fee. Both support TypeScript perfectly.

    conclusion

    Installing TypeScript requires installing NodeJS and then installing TypeScript using NPM.

    The editor recommends VS Code or WebStorm.

    Compile the TS file: TSC xx.ts

    Run the js file: node xx.js