Running and debugging TypeScript
Required plugins:
JavaScript Base
, JavaScript Debugger
- The plugins are bundled with RustRover and enabled by default.
With RustRover, you can run and debug TypeScript code.
note
Debugging of TypeScript client-side code is only supported in Google Chrome and in other Chromium-based browsers.
Because browsers process only JavaScript, you have to compile your client-side TypeScript code before running or debugging it.
Compilation can also produce source maps that set correspondence between your TypeScript code and the JavaScript code that is actually executed.
You can compile TypeScript with the built-in compiler or with other tools used either separately or as part of the build process.
By default, the built-in compiler outputs generated JavaScript files and sourcemaps next to the TypeScript file.
You can invoke compilation manually with the Compile actions from the TypeScript widget on the Status toolbar or enable automatic compilation on save.
Compilation errors are reported in the TypeScript Tool Window. This list is not affected by changes you make to your code and is updated only when you invoke compilation again.
The tool window shows up only after you first compile your TypeScript code manually. After that, the tool window is accessible via View | Tool Windows | TypeScript in the main menu or via the tool window bar.
Press to open settings and then select Languages & Frameworks | TypeScript.
Make sure the TypeScript Language Service checkbox is selected.
By default, the built-in compiler does not create source maps that will let you step through your TypeScript code during a debugging session. The compiler also by default processes either the TypeScript file in the active editor tab or all TypeScript files from the current project.
With a tsconfig.json file, you can modify this default behavior to generate source maps and compile only files from a custom scope.
In the Project tool window , select the folder where your TypeScript code is (most often it is the project root folder) and then select New | tsconfig.json File from the context menu.
To generate source maps during compilation, make sure the
sourceMap
property is set totrue
.Optionally:
To override the default compilation scope, which is the entire project, add the
files
property and type the names of the files to process in the following format:"files" : ["<file1.ts>","<file2.ts>"],
You may need to apply different TypeScript configurations to different files in your project.
It is not a problem if you arrange your sources so that all the files in each folder should be processed according to the same configuration. In such case you only have to create a separate tsconfig.json for each folder.
However, if you want to apply different rules to the files that are stored in the same folder, you need to create several configuration files and configure scopes for them.
Create as many tsconfig*.json configuration files as you need.
Open the Settings dialog () , go to Editor | File Types, and make sure the names of all these files match the patterns from the Typescript config file name pattern list.
In each *tsconfig*.json, specify the files to be processed according to its settings:
List the file names explicitly in the
files
field:"files" : ["<file1.ts>","<file2.ts>"],
Learn more from TSConfig Reference: Files.
In the
include
field, specify the file names or patterns:"include" : ["<pattern1>, <pattern2>"]
Learn more from TSConfig Reference: Include.
To skip some files whose names match the patterns listed in the
include
field, list their names or patterns in theexclude
field:"exclude" : ["<pattern3>, <pattern4>"]
Learn more from TSConfig Reference: Exclude.
note
RustRover doesn't use just the nearest tsconfig.*.json (from the list of files recognized as
Typescript config
file type). RustRover uses the nearest tsconfig.*.json in which a particular file is somehow specified – either explicitly in thefiles
field or through patterns in theinclude
andexclude
fields.
You can invoke compilation manually or have RustRover compile your code automatically every time the code is changed.
Alternatively, you can configure a build process, for example, with webpack, babel, or another tool. Learn more from webpack with TypeScript and Babel with TypeScript.
Click the Language Services widget on the Status bar.
tip
If no other language services are running against the current file, the title of the widget changes to TypeScriptt.
The TypeScript widget is shown on the Status bar all the time after you have opened a TypeScript file in the editor.
Click
.
In the Compile TypeScript popup, select one of the following options:
To compile the TypeScript code of the entire application, select Compile All.
Alternatively, select Compile TypeScript from the context menu of any open TypeScript file.
tip
You can also press and choose Compile TypeScript from the list.
To compile one file, select the path to it in the Compile TypeScript popup.
To compile files from a custom scope, make sure they are listed in the
files
property of your tsconfig.json as described above.In the Compile TypeScript popup, select the path to tsconfig.json.
Open the Languages & Frameworks | TypeScript settings page and select the Recompile on changes checkbox.
Because browsers process only JavaScript, you have to compile your client-side TypeScript code before running it.
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.
Do one of the following:
Choose View | Open in Browser from the main menu or press . Then select the desired browser from the list.
Hover over the code to show the browser icons bar:
. Click the icon that indicates the desired browser.
note
Debugging of TypeScript client-side code is only supported in Google Chrome and in other Chromium-based browsers.
Because browsers process only JavaScript, you have to compile your client-side TypeScript code before debugging it.
During compilation, there can also be generated source maps that set correspondence between your TypeScript code and the JavaScript code that is actually executed. As a result, you can set breakpoints in your TypeScript code, launch the application, and then step through your original TypeScript code, thanks to generated sourcemaps.
If your application is running on the built-in RustRover server, refer to Running a client-side TypeScript application above, you can also debug it in the same way as JavaScript running on the built-in server.

Most often, you may want to debug a client-side application running on an external development web server, for example, powered by Node.js.

Configure the built-in debugger as described in Configuring JavaScript debugger.
To enable source maps generation, open your tsconfig.json and set the
sourceMap
property totrue
, as described in Create a tsconfig.json file.Configure and set breakpoints in the TypeScript code.
Run the application in the development mode. Often you need to run
npm start
for that.Most often, at this stage TypeScript is compiled into JavaScript and source maps are generated. For more information, refer to Compile TypeScript into JavaScript.
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.
Go to Run | Edit Configurations. Alternatively, select Edit Configurations from the Run widget on the toolbar.
In the Edit Configurations dialog that opens, click the Add button (
) on the toolbar and select JavaScript Debug from the 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.
From the Run widget list on the toolbar, select the newly created configuration and click
next to it. The URL address specified in the run configuration opens in the browser and the Debug tool window appears.
You may need to refresh the page in the browser to get the controls in the Debug tool window available.
In the Debug tool window, proceed as usual: step through the program, stop and resume program execution, examine it when suspended, explore the call stack and variables, set watches, evaluate variables, view actual HTML DOM, and so on.