Typescript 在 Angular2 rc5 和 VisualStudio2015 的保存问题上编译

Typescript compile on save issues with Angular2 rc5 and VisualStudio2015

我在 VS2015 中安装了 Angular2 rc5,同时还安装了 MVC6。 tsconfig.json 中的 Typescript compileOnSave 设置一直存在问题。我已经完成了所有我能找到的修复,包括更改我的 PATH 环境变量中的打字稿版本,现在是 运行 1.8.x 而不是 1.0.x。我已经尝试在 VS 选项中进行设置以在保存时进行编译,这似乎没有什么不同。我试过使用 tsconfig.json 中的 watch 设置,这会导致我出现编译错误。

我决定使用 gulp-watch 和 gulp-typescript 功能让 Gulp 完成所有工作,在测试时我意识到当我删除在我的 tsconfig.json 文件中设置的 "outDir" 文件夹中的任何 .js 文件都会自动重新创建所有 .js 文件。我知道这是执行此操作的打字稿,因为当我更改 outDir 设置时,它会在该文件夹中执行。现在,如果我将 compileOnSave 设置为 false,它仍然会自动创建 .js 文件。奇怪的是,即使我只删除其中一个文件,它也会重新创建所有 .js 文件。我能够通过 gulp-watch 使用 'change' 和 'add' 事件来解决这个问题。

我的问题是,每次删除一个 js 文件时重新创建所有 js 和 js.map 文件是否正常?更重要的是,我怎样才能让它像预期的那样进行 compileOnSave?

这是我的 tsconfig.json 文件

 {
      "compileOnSave": true,
      "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noEmitOnError": false,
        "noImplicitAny": false,
        "outDir": "./app"
      },
      "exclude": [
        "node_modules",
        "wwwroot",
        "typings/main",
        "typings/main.d.ts"
      ]
    }

-- 更新--

我相信我已经解决了这个问题。看来,如果您使用 this method prescribed for issues with VS2015 typescript errors on compile ex) Invalid module name in augmentation, module '../../Observable' cannot be found, it will cause this compileOnSave problem. I undid the file swap I made and all is well. I believe this is a solution found in the Angular VS2015 quickstart,那么这可能会影响一些人。

我觉得如果你使用这个解决方案:https://github.com/Microsoft/TypeScript/issues/8518#issuecomment-229506507 要修复 vs2015 和各种版本的 Angular(我使用的是 rc5)常见的 "Invalid module name in augmentation, module '../../Observable' cannot be found." 问题,它可能会破坏 Typescript "compileOnSave" 功能。撤消修复后,我的 compileOnSave 又开始工作了。

我对这两个问题的解决方案是升级到 Typescript 2.0 beta。到目前为止,这已经解决了我所有的问题并且没有引入任何问题。