【问题标题】:Typescript .d.ts Compilation ErrorsTypescript .d.ts 编译错误
【发布时间】:2017-04-02 13:40:45
【问题描述】:

我正在使用 Visual Studio 2015 Pro 开发一个使用 Systemjs 和 Kendo UI Angular 2 组件的 .Net Core Angular 2 项目。

我正在使用 Gulp 将库文件从 node_modules 复制到“wwwroot/shared/lib”,并从 tsconfig.json 的编译中排除这两个目录。

在我包含一个 Kendo UI 模块之前一切正常,这会导致 typescript 编译“node_modules/@progress/[component-name]/dist/npm/js”目录中的 .d.ts 文件。

我在 tsconfig.json 中排除了 node_modules,所以我猜测 Kendo UI 组件代码以某种方式引用了 .d.ts 文件。

当我排除“wwwroot”而不是“wwwroot/shared/lib”时,项目编译不会出错(因为我所有的 .ts 文件都在“wwwroot”中)。

奇怪的是,当我将它改回“wwwroot/shared/lib”时,它仍然有效!但是一旦我重新启动 VS,我就会再次收到错误(?!)

所有错误都特定于“node_modules/@progress”文件夹中的 .d.ts 文件。 “node_modules/@angular”中有很多 .d.ts 文件不会导致任何问题,所以这必须特定于 Kendo UI 代码。

有什么方法可以阻止 VS 编译 .d.ts 文件,无论它们的位置如何?

这是我的 tsconfig:

"compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
},
"compileOnSave": true,
"exclude": [
    "node_modules",
    "wwwroot/shared/lib"
    //  ,
    //"wwwroot"
]

更新

看似随机,错误将从 6 跳转到 149 - 包括错误 TS2304: Cannot find name 'module', 'map', etc...

我尝试将"skipDefaultLibCheck": true 添加到 tsconfig,但没有成功。

添加"types": [ "node" ] 将导致 tsc.exe 以代码 1 退出,除非我执行排除“wwwroot”的技巧,然后运行项目,然后再次包含它。

在我这样做之后一切都正常运行 - 直到我重新启动 VS 并且一切都崩溃了。

更新 2

我安装了最新版本的 Typescript for Visual Studio 2015 (TypeScript_Dev14Full),它似乎已经解决了上述大部分问题,但我现在遇到了一个新错误:

“TS2309 构建:导出分配不能在具有其他导出元素的模块中使用。”在 \node_modules\@types\node\index.d.ts

错误出现两次,一次是 Project: "TypeScript Virtual Projects" 和 Project: "DevDashLocal"。

我使用最新版本的 .Net Core SDK 和 Typescript 重建了项目,并在新项目中收到相同的错误。

【问题讨论】:

  • 错误信息是什么?您的tsconfig.json 中有什么内容?
  • 错误是典型的 .d.ts 错误:重复标识符 'readonly'、'=' 预期、';'预期的。等等。它们只出现在我导入的剑道组件中。没有其他错误,错误的数量会根据我重启 VS 后打开的文件而波动。

标签: angular typescript asp.net-core asp.net-core-mvc kendo-ui-angular2


【解决方案1】:

这些错误似乎是由于安装了适用于 Visual Studio 2015 的过时版本的 Typescript。更新 TS 工具消除了引用 Kendo UI 的错误

【讨论】:

  • 我为 Typescript 升级了 Nuget 包,它为我修复了它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-06
  • 1970-01-01
  • 2019-09-22
  • 2018-04-05
  • 2017-08-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多