我如何“跑"WebStorm 中的 TypeScript 文件? [英] How I "Run" a TypeScript file in WebStorm?

查看:35
本文介绍了我如何“跑"WebStorm 中的 TypeScript 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 WebStorm IDE 中,我项目中的所有 .js(和 .jsx)文件都有一个关联的运行"命令,但是 .ts(或 .tsx)文件.

我相信我已经为 TypeScript 正确配置了我的项目,因为我至少能够从命令行运行 tsc (

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?

解决方案

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:

  • npm install -D ts-node typescript
  • in Node.js run configuration, specify --require ts-node/register as Node.js parameters:

这篇关于我如何“跑"WebStorm 中的 TypeScript 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆