vscode运行TypeScript

在Visual Studio Code中运行TypeScript文件,并且console.log(hello),有打印输出信息。

一. vscode安装Code Runner(.run)插件

二. 在文件的根目录下安装ts-node

执行命令: npm install -g ts-node typescript

bash 复制代码
npm install -g ts-node typescript

三. 运行原理

TypeScript -> JavaScript

四. 配置Visual Studio Code的settings.json新增/修改如下的配置

javascript 复制代码
{
  // 所有文件都在终端运行
  "code-runner.runInTerminal": true,
  // 运行前自动清屏,避免旧日志干扰
  "code-runner.clearPreviousOutput": true,
  // 运行前自动保存文件,避免用旧代码
  "code-runner.saveFileBeforeRun": true,
  // 指定解释器
  "code-runner.executorMap": {
    "typescript": "tsc $fileName && node $fileNameWithoutExt.js"
  }
}

五.测试

// hello.ts文件

// 右击文件,选择Run Code 运行

TypeScript 复制代码
const hello : string = "hello world"
console.log(hello);

// 输出结果

bash 复制代码
[Running] tsc hello.ts && node hello.js
hello world

[Done] exited with code=0 in 0.435 seconds
相关推荐
啊啊啊迈 旋棍14 小时前
【译】TypeScript 7 测试版已在 Visual Studio 2026 18.6 Insiders 3 中默认启用
ubuntu·typescript·visual studio
Yolanda_202216 小时前
在vscode终端中可使用pip,但是cmd终端中找不到命令 pip问题的解决
vscode·python·conda·pip
ITmaster073119 小时前
告别 IDE?Android CLI 来了,开发进入 AI Agent 时代
android·ide·人工智能
π同学20 小时前
ESP-IDF+vscode开发ESP32 联网篇第一讲——WIFI扫描
vscode·esp32c6·wifi scan
Wect21 小时前
TypeScript 完全指南
前端·javascript·typescript
漂移的电子1 天前
解决Vue3 + TypeScript + Vite搭建的项目,动态路由页面加载失败的最隐蔽原因
javascript·ubuntu·typescript
jiang_changsheng1 天前
详细教程__--PyCharm Terminal--切conda环境详解
ide·pycharm·conda
kisshyshy2 天前
《端侧大模型(三)“精装修”日记:进度条整容、聊天框首秀》
react.js·typescript·代码规范
方方洛2 天前
AI 教程系列-TUI 应用开发教程14-技能系统与可扩展性
前端·javascript·typescript
方方洛2 天前
AI 教程系列-TUI 应用开发教程05-大模型对话界面设计
前端·javascript·typescript