【问题标题】:Visual Studio 2017 TypeScript compilation errorsVisual Studio 2017 TypeScript 编译错误
【发布时间】:2017-08-28 11:59:26
【问题描述】:

我正在尝试将 ASP.NET Core 应用程序转换为 VS 2017。不幸的是,我无法编译该站点,因为我不断收到 TypeScript 错误。我宁愿 VS 甚至不碰我的 TypeScript,因为我正在使用 Webpack 进行实际的构建和捆绑。

该站点中有一个 Angular 2 应用程序,包括一些测试。这是一个示例错误:

错误 TS2665 构建:扩充中的模块名称无效。模块 'angular-mocks/ngMock' 解析为无类型模块 'D:/myapp/source/MySite/node_modules/angular-mocks/ngMock.js',其中 无法增强。 MySite D:\myapp\source\MySite\node_modules\@types\angularjs\angular-mocks.d.ts 8

我的 app/tsconfig.json 文件如下所示:

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "experimentalDecorators": false,
    "sourceMap": false,
    "module": "commonjs",
    "moduleResolution": "node",
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ],

    "lib": [
      "es2016",
      "dom"
    ]
  },
    "exclude": [
    "../node_modules",
    "../wwwroot"
  ],
  "compileOnSave": false
}

有没有办法告诉 VS 在构建时完全忽略我的 TypeScript?我不知道它为什么还要查看这些文件。

【问题讨论】:

  • 您的 Visual Studio 可能正在使用旧版本的 TypeScript 编译器。你能确认它实际上使用的是最新的 TypeScript 吗?
  • 我不认为我可以选择 2017 年,是吗?我无法安装更新的版本。据我所知,它使用的是 2.1,这是 2017 年的版本。
  • 我的tsconfig.json 文件位置比你的高一级...它有这个"baseUrl": "src", 而我什至没有"exclude" 设置。
  • 不确定这是否有帮助,也许值得一试:developercommunity.visualstudio.com/answers/11741/view.html
  • @RosdiKasim 给我的链接是 404。

标签: visual-studio angular typescript visual-studio-2017


【解决方案1】:

如果您不希望 VS 2017 为您编译 Typescript,请参阅TypeScript Handbook 的以下文档,了解如何在 MSBuild 中禁用编译。

TypeScriptCompileBlocked

如果您使用不同的构建工具来构建您的项目(例如 gulp、grunt 等)和 VS 用于开发和调试 体验,设置 <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> 在你的 项目。这应该给你所有的编辑支持,但不是 按 F5 时构建。

【讨论】:

    猜你喜欢
    • 2017-12-23
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2019-04-01
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多