安装typescript:npm安装
npm i -g typescript
ts编译成es5:
tsc *.ts
创建tsconfig.json文件: 生成配置文件
tsc --init
自动编译:vscode: 终端--->运行任务--->--->typescript--->监听tsconfig.json
遇到的问题:
运行tsc *ts的时候报错:
tsc : 无法加载文件 C:\Users\tc\AppData\Roaming\npm\tsc.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ tsc index.ts
tsc : 无法加载文件 C:\Users\tc\AppData\Roaming\npm\tsc.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ tsc index.ts
+ ~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess

问题原因:
powershell对于脚本的执行有着严格的安全限制
解决方法:
管理员身份运行windows powershell ,开发人员需频繁使用powershell脚本,允许本地脚本运行,可在命令行输入:
set-ExecutionPolicy RemoteSigned -Scope CurrentUser
选择 A 或者 Y,回车。

浙公网安备 33010602011771号