我有一个使用 Yeoman gulp typescript generator 生成的 Angular 应用程序。
在构建打字稿期间突然没有任何明显的原因(项目更改)开始抛出错误:
.tmp/typings/moment/moment-node.d.ts(6,16): error TS2300: Duplicate identifier 'moment'.
[22:08:34] [TypeScript] TypeScript error: .tmp/typings/moment/moment-node.d.ts(6,16): error TS2300: Duplicate identifier 'moment'.
.tmp/typings/moment/moment.d.ts(8,13): error TS2300: Duplicate identifier 'moment'.
请参阅以下文件的以下内容以供参考。我从gulp script
任务中删除了 'tsd:install' 以防止构建覆盖 d.ts 文件和 tsd.d.ts 文件。然后尝试修改 tsd.d.ts 以解决问题(我尝试删除 moment-node、moment、change order,我还尝试编辑 moment.d.ts 和 moment-node.d.ts,没有任何效果:/) .
我的 tsd.json 文件:
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": ".tmp/typings",
"bundle": ".tmp/typings/tsd.d.ts"
}
我的 script.js (gulp taks):
'use strict';
var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var browserSync = require('browser-sync');
var $ = require('gulp-load-plugins')();
var tsProject = $.typescript.createProject({
target: 'es5',
sortOutput: true
});
gulp.task('scripts', ['tsd:install'], function () {
return gulp.src(path.join(conf.paths.src, '/app/**/*.ts'))
.pipe($.sourcemaps.init())
.pipe($.tslint())
.pipe($.tslint.report('prose', { emitError: false }))
.pipe($.typescript(tsProject)).on('error', conf.errorHandler('TypeScript'))
.pipe($.concat('index.module.js'))
.pipe($.sourcemaps.write())
.pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/app')))
.pipe(browserSync.reload({ stream: true }))
.pipe($.size())
});
生成的 tsd.d.ts:
/// <reference path="angular-local-storage/angular-local-storage.d.ts" />
/// <reference path="angular-ui-router/angular-ui-router.d.ts" />
/// <reference path="angularjs/angular-animate.d.ts" />
/// <reference path="angularjs/angular-cookies.d.ts" />
/// <reference path="angularjs/angular-mocks.d.ts" />
/// <reference path="angularjs/angular-resource.d.ts" />
/// <reference path="angularjs/angular-sanitize.d.ts" />
/// <reference path="angularjs/angular.d.ts" />
/// <reference path="bootstrap/bootstrap.d.ts" />
/// <reference path="d3/d3.d.ts" />
/// <reference path="jquery/jquery.d.ts" />
/// <reference path="moment/moment.d.ts" />
/// <reference path="moment/moment-node.d.ts" />
/// <reference path="toastr/toastr.d.ts" />