GoLand 2018.2 Help

Running and debugging TypeScript

You can write your application in TypeScript and then run and debug it exactly the same way as client-side JavaScript, Node.js, React, Angular, etc. applications.

Before running or debugging, you need to compile your TypeScript code into JavaScript. GoLand lets you do that on the fly, through integration with the TypeScript Compiler, as described in Verifying TypeScript and compiling it into JavaScript. You can also use another tool, for example, webpack. Learn more from the TypeScript Official website.

Running a client-side TypeScript application

  1. Compile the TypeScript code into JavaScript.

  2. In the editor, open the HTML file with a reference to the generated JavaScript file. This HTML file does not necessarily have to be the one that implements the starting page of the application.

  3. Do one of the following:
    • Choose View | Open in Browser on the main menu or press Alt+F2. Then select the desired browser from the pop-up menu.

    • Hover your mouse pointer over the code to show the browser icons bar: browserIcons Click the icon that indicates the desired browser.

Debugging TypeScript

Most often, you may want to debug a client-side application running on an external development web server, e.g. powered by Node.js. If your application is running on the built-in GoLand server, you can also debug it in the same way as JavaScript running on the built-in server.

With GoLand, you set breakpoints in the original TypeScript code instead of the compiled JavaScript that is actually executed. GoLand recognizes and processes breakpoints in TypeScript using source maps.

To generate source maps during compilation

  • Open the tsconfig.json file and make sure the sourceMap property is set to true.

To debug a TypeScript application running on an external web server

  1. Compile the TypeScript code into JavaScript, see Compiling TypeScript. Make sure source maps are generated.

  2. Configure and set breakpoints in the TypeScript code.

  3. Run the application in the development mode. Often you need to run npm start for that. When the development server is ready, copy the URL address at which the application is running in the browser - you will need to specify this URL address in the run/debug configuration.

  4. Choose Run | Edit Configuration from the main menu, click icons general add on the toolbar and select JavaScript Debug from the pop-up list. In the Run/Debug Configuration: JavaScript Debug dialog that opens, specify the URL address at which the application is running. This URL can be copied from the address bar of your browser as described in Step 3 above.

  5. Choose the newly created configuration in the Select run/debug configuration drop-down list on the toolbar and click icons actions startDebugger svg. The URL address specified in the run configuration opens in the chosen browser and the Debug Tool Window appears.

  6. In the Debug tool window, proceed as usual: step through the program, stop and resume the program execution, examine it when suspended, view actual HTML DOM, etc.

Last modified: 12 October 2018