VSCode插件 code runner运行TypeScript

运行原理:

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
发布了1392 篇原创文章 · 获赞 347 · 访问量 123万+

猜你喜欢

转载自blog.csdn.net/mouday/article/details/103800887