安装编译 TS 的工具包
Node.js只认识JS代码,需要将TS代码转化为JS代码,才能运行。
# 全局安装npm i -g typescript# 查看版本tsc -v
编译方式
手动编译 ts
- 编写
hello.ts tsc hello.ts将TS编译为JSnode hello.js
问题:**vscode**禁止运行脚本?
管理员身份打开Windows PowerShell
>get-ExecutionPolicy>set-ExecutionPolicy RemoteSigned> y
简化手动编译 ts
# 全局安装 ts-node 包npm i -g ts-node# 运行 tsts-node hello.ts
自动编译 ts
- 生成配置文件
tsc --init
- 修改配置文件
tsconfig.json
"outDir": "./js""strict": false
- 启动监视任务
终端 -> 运行任务 -> 显示所有任务 -> 监视tscconfg.json
