I am currently working on an Angular 2 beta 8 project with gulp and facing a specific issue.
The problem arises when gulp-typescript is unable to check the types. Here is the gulp task configuration:
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'))
})
I first compile to ES6 and then use traceur as typescript shows fewer errors this way. The shell log displays:
[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)
I am seeking advice on how to include typescript definition files. I have attempted adding these files to gulp.src
like so:
gulp.src(['app/**/*.ts', 'node_modules/angular2/**/*.d.ts)
However, this results in duplicated definition files errors.
I have also tried adding typing options to package.json:
"typings": 'node_modules/angular2/platform/browser.d.ts'
But this file contains imports that are not detected recursively.
Therefore, I am looking for guidance on resolving this issue.
Despite the newer versions of angular including angular2.d.ts, they do not cover all necessary definitions. I find it puzzling why I need to use typescript definition files when Angular itself is written in typescript.
Is there a way to import angular typescript from node_modules and compile it using the typescript compiler?