“重复标识符" Angular2和TSD错误 [英] "Duplicate identifier" errors with Angular2 and TSD

查看:99
本文介绍了“重复标识符" Angular2和TSD错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将项目从Angular 1转换为Angular 2.

I'm trying to convert a project from Angular 1 to Angular 2.

这是客户&服务器项目中包含一些通用代码(因此我将其保存在一起).我想在客户端使用Angular 2,所以我遵循了 ng2快速入门.我目前正在尝试在我的项目中构建它.

This is a client & server project with some common code (so I keep it together). I want to use Angular 2 on the client side so I followed the ng2 QuickStart. I am currently trying to build it inside my project.

我正在使用TSD来管理依赖项类型.其中一些依赖项,例如socket.io依赖于node.d.ts. 我的问题是angular2已经公开了node.d.ts并创建了环境定义,因此当我想将TSDangular2一起使用时,两个定义之间会发生冲突: typings\node\node.d.ts(961,9): error TS2300: Duplicate identifier 'path'.

I am using TSD to manage my dependencies typings. Some of these dependencies like socket.io rely on node.d.ts. My problem is that angular2 already expose node.d.ts and create an ambient definition so when I want to use TSD with angular2 I get a conflict between the two definitions : typings\node\node.d.ts(961,9): error TS2300: Duplicate identifier 'path'.

这是我的大任务:

gulp.task('build.conflict', function(){

  var browserProject = tsc.createProject('browser.tsconfig.json', {
    typescript: typescript
  });

  var src = [
    'src/browser/**/*.ts',
    'typings/**/*.d.ts' // commenting out this line results in unknown modules
  ];

  var result = gulp.src(src)
    .pipe(tsc(browserProject));

  return result.js
    .pipe(gulp.dest('build/browser'));

});

我还设置了一个简单的存储库来说明我的问题. 我如何解决此错误,同时仍保持我的TSD键入. (最好的解决方案是防止angular2公开其内部的node.d.ts)

I also set up a simple repository demonstrating my issue. How can I solve this error while still keeping my TSD typings. (The best solution would be to prevent angular2 to expose its internal node.d.ts)

推荐答案

如果您开始使用Typings,则只能允许从tsconfig.json中的浏览器依赖项中发现*.d.ts. 此处是John Papa的NgConf演示中的一个很好的例子.

If you started using Typings, you could only allow discovering *.d.ts from browser dependencies in tsconfig.json. Here is an excellent example at John Papa's NgConf demo.

更新:每次键入> 1.0.0时,此值已过时.

UPDATE: This is outdated per Typings > 1.0.0.

这篇关于“重复标识符" Angular2和TSD错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆