“Duplicate identifier” errors with Angular2 and TSD

和自甴很熟 提交于 2019-12-23 12:32:23

问题


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

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.

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'.

Here is my gulp task :

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'));

});

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)


回答1:


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.

UPDATE: This is outdated per Typings > 1.0.0.



来源:https://stackoverflow.com/questions/34207110/duplicate-identifier-errors-with-angular2-and-tsd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!