准备环境
安装VS code
下载地址
https://code.visualstudio.com/
- 选择OS对应的VS Code下载,下载完成后安装并启动
安装typescript
需要提前安装node js
- 安装typescript
npm install -g typscript
编写hello.ts测试
- 新建一个文件
- 保存为hello.ts
- 编写TypeScript
console.log("11111");
class Dog {
name():void {
console.log("labuladuo Dog ");
}
}
var dog=new Dog();
dog.name();
- 运行 tsc hello.ts
tsc:无法加载文件,提示因为在此系统上禁止运行脚本
- 按win+s 搜索 powershell,以管理员身份运行PowerShell
- 查看执行策略
get-ExecutionPolicy -List
- 修改当前用户的执行策略
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
输入Y确定
- 查看修改后的执行策略
get-ExecutionPolicy -List
- 编译Typescrit
tsc hello.ts
按ctrl+j 打开terminal然后编译hello.ts文件
- 查看编译后的文件hello.js文件
- 运行node hello.js
参考
https://docs.microsoft.com/zh-cn/previous-versions/windows/powershell-scripting/hh847748(v=wps.640)?redirectedfrom=MSDN