0
点赞
收藏
分享

微信扫一扫

VSCode插件 code runner运行TypeScript

一脸伟人痣 2022-02-28 阅读 87


运行原理:

TypeScript -> JavaScript

1、VSCode先安装插件​​code runner​

2、安装 typescript

npm install -g typescript

3、运行ts文件

(1)方法一:通用方法

配置settings.json

// 指定解释器
"code-runner.executorMap": {
"typescript": "tsc $fileName && node $fileNameWithoutExt.js"
},

下表是 Code Runner 支持的自定义参数:

参数

说明

$workspaceRoot

当前工程目录路径

$dir

要运行的代码文件所在的目录

$dirWithoutTrailingSlash

要运行的代码文件所在的目录(不带尾后斜杆)

$fullFileName

要运行的代码文件全路径

$fileName

要运行的代码文件名称

$fileNameWithoutExt

要运行的代码文件名称(不带后缀名)

$driveLetter

要运行的代码文件所在盘符(只用于 Windows 系统)

$pythonPath

Python 解释器路径

(2)方法二:ts-node

npm install -g ts-node

测试

const hello : string = "hello world"
console.log(hello);

运行结果

[Running] ts-node "/Desktop/demo.ts"
hello world

[Done] exited with code=0 in 0.942 seconds



举报

相关推荐

0 条评论