Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugultopu/edbe1c95891538e3a7395597adff6087 to your computer and use it in GitHub Desktop.
Save ugultopu/edbe1c95891538e3a7395597adff6087 to your computer and use it in GitHub Desktop.
  • Install Visual Studio Code.

  • Install Node.js. Although Visual Studio Code comes with support for the JavaScript and TypeScript languages, as well as Node.js debugging, we still need to install the Node.js runtime on our machine.

  • Create a directory for our project and change into it:

    mkdir sample-typescript-application && cd sample-typescript-application
    
  • Install the TypeScript runtime. Just like the step of installing the Node.js runtime, this step is still necessary even though Visual Studio Code comes with support for the JavaScript and TypeScript languages. If we skip this step, the "TypeScript Watch" command that we'll use in one of the following steps will not work. To install the TypeScript runtime:

    echo '{}' > package.json && npm install typescript --save-dev
    
  • Create a TypeScript file and save it with a .ts extension.

  • Create a "tsconfig.json" file with the following content:

    {
      "compilerOptions": {
        "sourceMap": true,
        // Optional. Uncomment for more strict type checking. 
        // "strict": true,
      }
    }
  • On Visual Studio Code:

    • Open Command Palette by pressing SHIFTCMDP.

    • Type "task" and select "Tasks: Run task".

    • From the "contributed" section, select the TypeScript folder.

    • Select "tsc: watch - tsconfig.json".

  • That's it! Now you can:

    • Go to any TypeScript file in this folder.
    • Place a breakpoint on any line of it by clicking on the area to the left of line numbers.
    • Start debugging it by:
      • Selecting the "Run and Debug" (or by pressing SHIFTCMDD).
      • Clicking on the "Run and Debug" button.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment