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
相关推荐
濮水大叔15 小时前
在大型 Vue 项目中,如何有效管理复杂的状态?“散装版” vs “套装版”
前端·vue.js·typescript
谷哥的小弟2 天前
TypeScript数组类型
javascript·typescript
退休倒计时2 天前
【每日一题】LeetCode 199. 二叉树的右视图 TypeScript
算法·leetcode·typescript
Tian_Hang2 天前
Eclipse Ditto 的权限策略
java·服务器·前端·网络·ide·ubuntu·eclipse
Tian_Hang2 天前
Eclipse Mosquitto 安装及介绍
java·运维·服务器·ide·sql·mysql·eclipse
星云_byto2 天前
五分钟从零配置好VSCode + Claude Code + DeepSeek V4 Pro
ide·vscode·编辑器·cursor·codex·claude code·deepseekv4
前端之虎陈随易2 天前
编程语言级别的Skill市场,AI Agent 的未来形态
前端·vue.js·人工智能·typescript·node.js
诚信定制8392 天前
Typora插件开发指南:打造专属IDE式写作环境
ide
Tian_Hang3 天前
Eclipse Ditto 物模型相关代码
java·运维·服务器·ide·eureka·eclipse
Tian_Hang3 天前
Eclipse Ditto 节流机制
java·ide·eclipse