typescriptwebstorm

How I "Run" a TypeScript file in WebStorm?


In my WebStorm IDE, all .js (and .jsx) files in my project have an associated "Run" command, but this feature is absent from .ts (or .tsx) files.

I believe I have correctly configured my project for TypeScript, as I am able to at least run tsc from the command line (with somewhat unexpected results), but am surprised that I can't simply do this from within the IDE.

Does WebStorm support single file TypeScript compilation and running? Does enabling this require some specific non-default configuration of the IDE?


Solution

  • Running Typescript files directly is not supported, as they can't be run with Node.js. You have to either pre-compile your code with tsc and then invoke Run on the compiled js file, or use on-the-fly compilation with ts-node:

    enter image description here