您当前的位置: 首页 >  彭世瑜 vscode

VSCode插件 code runner运行TypeScript

彭世瑜 发布时间:2020-01-02 11:17:22 ,浏览量:4

运行原理:

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 系统)
$pythonPathPython 解释器路径

(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
关注
打赏
查看更多评论

彭世瑜

暂无认证

  • 4浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录