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
相关推荐
浪遏13 小时前
recruitment-cli:让 AI 接手求职招聘,从架构到一次发送超时
架构·typescript·node.js
律宏阔1 天前
微信小程序 + Taro 从 ESLint 迁移到 Oxlint 让项目代码检查速度提升近 12 倍
前端·typescript·eslint
瓦瓦gogo1 天前
从一个 TypeScript 函数开始理解 MCP 协议
linux·ubuntu·typescript
拼图2091 天前
VSCode 正则表达式使用指南
ide·vscode·正则表达式
ZhengEnCi2 天前
Hono 4 多库多模型服务的企业级 Monorepo 目录结构:npm workspaces 与 Turborepo 该怎么分层
typescript
#六脉神剑2 天前
myBuilder 11 月新版本:AI辅助设计
ide·人工智能·低代码·ai·mybuilder
小李不困还能学2 天前
VSCode_RemoteSSH_一直卡在下载服务器_解决教程
服务器·ide·vscode
浪遏3 天前
从命令到工作流:juejin-cli 如何让写作自动化更可靠
typescript
浪遏3 天前
07|网页上看着正常,导出的 PDF 为什么还会变样
typescript
浪遏3 天前
03|自动保存真正难的部分,是保存期间又发生了修改
typescript