Angular2 beta 8包含来自node_modules的Typescript定义文件

时间:2016-03-06 18:52:30

标签: typescript angular

我有一个有角度的2 beta 8项目,并且有工作。

问题是当gulp-typescript无法检查类型时。 gulp任务如下:

gulp.task('ts', function() {
  gulp.src('app/**/*.ts')
  .pipe(ts({
    target: 'ES6',
    emitDecoratorMetadata: true,
    experimentalDecorators: true
  }))
  .pipe(rename({ extname: '' }))
  .pipe(traceur({
      modules: 'instantiate',
      moduleName: true,
      annotations: true,
      types: true,
      memberVariables: true
  }))
  .pipe(rename({ extname: '' }))
  .pipe(gulp.dest('build'))
})

我首先编译ES6,并在原因打字稿之后使用traceur显示更少的错误。 我展示了shell日志:

[19:23:37] Using gulpfile ~/front/gulpfile.js
[19:23:37] Starting 'dependencies'...
[19:23:37] Finished 'dependencies' after 15 ms
[19:23:37] Starting 'ts'...
[19:23:37] Finished 'ts' after 5.96 ms
[19:23:37] Starting 'html'...
[19:23:37] Finished 'html' after 1.15 ms
[19:23:37] Starting 'default'...
[19:23:37] Finished 'default' after 3.13 μs
app/app.ts(1,28): error TS2307: Cannot find module 'angular2/platform/browser'.
app/components/component.ts(1,25): error TS2307: Cannot find module 'angular2/core'.
[19:23:39] TypeScript: 2 semantic errors
[19:23:39] TypeScript: emit succeeded (with errors)

我想知道如何包含打字稿定义文件。 我已尝试将此文件添加到gulp.src中,如:

gulp.src(['app/**/*.ts', 'node_modules/angular2/**/*.d.ts)

但是显示:重复的定义文件错误。

我甚至试图在package.json中添加输入选项,如:

"typings": 'node_modules/angular2/platform/browser.d.ts'

但是这个文件的导入没有被递归检测到。

所以...有任何建议吗?

角度的持续版本包括angular2.d.ts但不是这个。我不会感到不安,为什么我应该使用typescript定义文件,无论angular是用typescript写的。

是否可以从node_modules导入angular typescript并通过typescript编译器进行编译?

1 个答案:

答案 0 :(得分:1)

您需要在gulp文件的ts函数中使用node_modules/angular2/...。 这将告诉TypeScript编译器在select a.userid, b.tagid, b.chaname from table1 a,table2 b where b.tagid not in (select tagid from tabel1)

中查找定义
相关问题