分享自己亲测过的Visualstudio 2019中开发Typescript时,设置自动编译生成js,无需手工运行命令生成的方法。

步骤1)右键web项目,添加 tsconfig.json文件.

步骤2)确保配置如下,编译版本可自行设置,这里主要关注编译目标目录和自动编译设置:

{
  "compileOnSave": true, //typescript保存的时候自动编译,生成js
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5" //标准
  },
  //这里是排除的ts文件目录
  "exclude": [
    "node_modules"
  ],
  //这里是包含的ts文件目录
  "include": [
    "wwwroot/js/ts/*"
  ]
}