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
相关推荐
纪伊路上盛名在27 分钟前
windows 配置vscode x11转发
ide·vscode·编辑器
comedate4 小时前
Cursor 和 GitHub Copilot 怎么选?2026 年 AI 编程助手对比
ide·ai编程·cursor·github copilot
2501_915106326 小时前
KXApp 的 VS Code 真机调试:按下 Cmd+R 之后发生了什么
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
Patrick_Wilson7 小时前
悬浮提示从哪来:LSP、tsserver 与 .d.ts
typescript·npm·前端工程化
hkj88087 小时前
VsCode的使用
ide·vscode·编辑器
oldnicke21 小时前
理解 TRAE 的 Agent + IDE 思路:用一个 Markdown 检查器拆解完整交付
typescript
钱栈up21 小时前
GitHub 热榜实测|REA:用 Agent 逆向一切
typescript·开源·github
keyipatience1 天前
TypeScript学习(1)
前端·javascript·学习·typescript·html·css3
夏虫不可与之言冰1 天前
第三课 点亮 LED 与定时器非阻塞闪烁
c语言·c++·vscode·单片机·嵌入式硬件·物联网
丑大王1 天前
ultralytics 环境安装与正确使用Vscode
ide·yolo·编辑器