本文介绍了2角多次错误TS2300:重复标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

系统configuraions

system configuraions


  • 的Ubuntu 14.04

  • 节点-v => V5.6.0

  • 故宫-v => 3.7.1

  • 分型最新版本(不知道怎么弄的版本细节)

在与angular2第一次工作
我的文件夹中的样本/服务器结构如下

while working with angular2 first time onmy folder sample/server structure is below

|-- server.js
|-- server.ts
|-- tsconfig.json
|-- typings
|   |-- browser
|   |   `-- ambient
|   |       |-- express
|   |       |   `-- express.d.ts
|   |       |-- mime
|   |       |   `-- mime.d.ts
|   |       |-- node
|   |       |   `-- node.d.ts
|   |       `-- serve-static
|   |           `-- serve-static.d.ts
|   |-- browser.d.ts
|   |-- main
|   |   `-- ambient
|   |       |-- express
|   |       |   `-- express.d.ts
|   |       |-- mime
|   |       |   `-- mime.d.ts
|   |       |-- node
|   |       |   `-- node.d.ts
|   |       `-- serve-static
|   |           `-- serve-static.d.ts
|   `-- main.d.ts
`-- typings.json

tsconfig.json

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
   "files": [
    "./server/typings/main.d.ts",
    "./server/server.ts"
  ],
  "exclude": [
        "node_modules",
        // even used ../node_modules as the folder is located above this folder
        "typings/browser.d.ts",
        "typings/browser"
  ]
}

typings.json

{
  "ambientDependencies": {
    "express": "github:DefinitelyTyped/DefinitelyTyped/express/express.d.ts#d1f6bde13f2209be42e86c3686761e8bfcbb50a5",
    "mime": "github:DefinitelyTyped/DefinitelyTyped/mime/mime.d.ts#d1f6bde13f2209be42e86c3686761e8bfcbb50a5",
    "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#aee0039a2d6686ec78352125010ebb38a7a7d743",
    "serve-static": "github:DefinitelyTyped/DefinitelyTyped/serve-static/serve-static.d.ts#0fa4e9e61385646ea6a4cba2aef357353d2ce77f"
  }
}

gulpgile.js

var path = require('path');
var gulp = require('gulp');
var gutil = require('gulp-util');
var ts = require('gulp-typescript');

gulp.task('log', function() {
  gutil.log('== My Log Task ==')
});

gulp.task('buildServer', function () {
    var tsProject = ts.createProject('./server/tsconfig.json');
    return gulp.src('./server/**/*.ts')
        .pipe(ts(tsProject))
        .js
        .pipe(gulp.dest('./server'))
});

main.d.ts和browser.d.ts

/// <reference path="main/ambient/express/express.d.ts" />
/// <reference path="main/ambient/mime/mime.d.ts" />
/// <reference path="main/ambient/node/node.d.ts" />
/// <reference path="main/ambient/serve-static/serve-static.d.ts" />

运行时

usernam@hostname:~/sample$ gulp buildServer

它给类似下面的错误655,参考node.d.ts的每一行

it gives 655 errors similar to below , referencing every line of node.d.ts

服务器/分型/浏览器/环境/节点/ node.d.ts(754,9):错误TS2300:重复标识内部

...结果
....

...
....

服务器/分型/主/环境/节点/ node.d.ts(1943,18):错误TS2300:
重复的标识符域。

...

......

服务器/分型/主/环境/服务静电/服务-static.d.ts(85,5):
错误TS2300:重复标识符出口='

和最后它停止

[22:38:56] TypeScript: 655 semantic errors
[22:38:56] TypeScript: emit succeeded (with errors)

更新

我注意到它首先给出了错误的主/ 的文件夹比的浏览器/ 的文件夹

我的猜测是,问题是与 gulpfile.js 的;
 下面做出改变gulpfile.js

my guess is that issue is with gulpfile.js ; make below change in gulpfile.js

返回gulp.src('./服务器/ ** / *。TS')返回 gulp.src('./服务器/主/ *。TS')

一饮而尽buildServer 运行,但瞬间完成。


  • 这是什么的.js 吗?

  • 可以 gulp.dest gulp.src 指出在同一个文件夹?

  • What does this .js do?
  • Can gulp.dest and gulp.src pointed on same folder?

请所说的其实是围绕解决this.I看到在网上也没有找到任何东西,现在工作的工作。

Please suggest what is the work around to fix this.I have seen over the web but couldn't find anything working for now.

推荐答案

尝试只包括所有的 * TS 文件不含全部 *。d.ts 除了主.d.ts 。

Instead of including all *.ts files including the definition files try just including all *.ts files excluding all *.d.ts files except for main.d.ts.

gulp.src(['server/**/*.ts', '!server/**/*.d.ts', 'server/typings/main.d.ts'])

或(不是100%的订货在水珠的工作方式把我的头顶部)

or (not 100% on how the ordering works in glob off the top of my head)

gulp.src(['server/**/*.ts', 'server/typings/main.d.ts', '!server/**/*.d.ts'])

更新:我结束了使用 merge2 两个 gulp.src 流相结合

Update: I ended up using merge2 to combine two gulp.src streams.

var gulp = require('gulp');
var merge = require('merge2');
var typescript = require('gulp-typescript');

gulp.task('build', function() {
    var tsFiles = gulp.src('server/**/*.ts', '!server/typings/**');

    return merge(tsFiles, gulp.src('server/typings/main.d.ts'))
        .pipe(typescript(...));
});

这篇关于2角多次错误TS2300:重复标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 05:12