2016-05-15 79 views
0

我用gulp编译打字稿时几乎没有问题。我设置在我tsconfig排除目录,但我得到* .d.ts错误:Typescript express - gulp排除编译错误

typings/browser/ambient/node/index.d.ts(1965,18): error TS2300: Duplicate identifier 'Transform'. 
typings/browser/ambient/node/index.d.ts(1987,18): error TS2300: Duplicate identifier 'PassThrough'. 
typings/browser/ambient/node/index.d.ts(1992,9): error TS2300: Duplicate identifier 'showHidden'. 
typings/browser/ambient/node/index.d.ts(1993,9): error TS2300: Duplicate identifier 'depth'. 
typings/browser/ambient/node/index.d.ts(1994,9): error TS2300: Duplicate identifier 'colors'. 
typings/browser/ambient/node/index.d.ts(1995,9): error TS2300: Duplicate identifier 'customInspect'. 
typings/browser/ambient/node/index.d.ts(2056,5): error TS2300: Duplicate identifier 'export='. 
typings/browser/ambient/node/index.d.ts(2064,9): error TS2300: Duplicate identifier 'isRaw'. 
typings/browser/ambient/node/index.d.ts(2066,9): error TS2300: Duplicate identifier 'isTTY'. 
typings/browser/ambient/node/index.d.ts(2069,9): error TS2300: Duplicate identifier 'columns'. 
typings/browser/ambient/node/index.d.ts(2070,9): error TS2300: Duplicate identifier 'rows'. 
typings/browser/ambient/node/index.d.ts(2071,9): error TS2300: Duplicate identifier 'isTTY'. 
typings/browser/ambient/node/index.d.ts(2078,18): error TS2300: Duplicate identifier 'Domain'. 
typings/browser/ambient/serve-static/index.d.ts(85,5): error TS2300: Duplicate identifier 'export='. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/body-parser/index.d.ts(138,5): error TS2300: Duplicate identifier 'export='. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(22,9): error TS2300: Duplicate identifier 'path'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(23,9): error TS2300: Duplicate identifier 'stack'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(81,9): error TS2300: Duplicate identifier 'all'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(82,9): error TS2300: Duplicate identifier 'get'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(83,9): error TS2300: Duplicate identifier 'post'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(84,9): error TS2300: Duplicate identifier 'put'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(85,9): error TS2300: Duplicate identifier 'delete'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(86,9): error TS2300: Duplicate identifier 'patch'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(87,9): error TS2300: Duplicate identifier 'options'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(88,9): error TS2300: Duplicate identifier 'head'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(107,9): error TS2300: Duplicate identifier 'ma 
ge'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(108,9): error TS2300: Duplicate identifier 'signed'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(109,9): error TS2300: Duplicate identifier 'expires'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(110,9): error TS2300: Duplicate identifier 'httpOnly'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(111,9): error TS2300: Duplicate identifier 'path'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(112,9): error TS2300: Duplicate identifier 'domain'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(113,9): error TS2300: Duplicate identifier 'secure'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(145,9): error TS2300: Duplicate identifier 'headers'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(242,9): error TS2300: Duplicate identifier 'accepted'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(293,9): error TS2300: Duplicate identifier 'protocol'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(300,9): error TS2300: Duplicate identifier 'secure'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(307,9): error TS2300: Duplicate identifier 'ip'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(317,9): error TS2300: Duplicate identifier 'ips'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(330,9): error TS2300: Duplicate identifier 'subdomains'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(335,9): error TS2300: Duplicate identifier 'path'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(340,9): error TS2300: Duplicate identifier 'hostname'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(345,9): error TS2300: Duplicate identifier 'host'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(352,9): error TS2300: Duplicate identifier 'fresh'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(359,9): error TS2300: Duplicate identifier 'stale'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(364,9): error TS2300: Duplicate identifier 'xhr'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(367,9): error TS2300: Duplicate identifier 'body'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(370,9): error TS2300: Duplicate identifier 'cookies'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(372,9): error TS2300: Duplicate identifier 'method'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(374,9): error TS2300: Duplicate identifier 'params'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(376,9): error TS2300: Duplicate identifier 'user'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(378,9): error TS2300: Duplicate identifier 'authenticatedUser'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(388,9): error TS2300: Duplicate identifier 'query'. 
/Users/petrtomasek/Projects/expressTypescript/typings/main/ambient/express-serve-static-core/index.d.ts(390,9): error TS2300: Duplicate identifier 'route'. 

这是错误的只是一部分,但一切都是从同一个文件夹。 我gulpfile

var tsProject = ts.createProject('tsconfig.json', { typescript: require('typescript') }); 

gulp.task('Build_typescript', function() { 
return tsProject.src([paths.typescriptDir + "*.ts", "!" + paths.documentRoot + "baseDir.ts", "!" + paths.documentRoot + "_all.d.ts"]) 
    .pipe(plumber()) 
    .pipe(sourcemaps.init()) 
    .pipe(ts(tsProject)) 
    .pipe(debug()) 
    .pipe(sourcemaps.write(".")) 
    .pipe(gulp.dest(".")); 
}); 

与ES5 tsconfig从Angular2

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false 
    }, 
    "exclude": [ 
    "node_modules", 
    "typings/main", 
    "typings/main.d.ts" 
//"typings/browser", 
//"typings/browser.d.ts" 
    ] 
} 

我所有的* .d.ts引用我在一个文件中_all.d.ts

/// <reference path="../node_modules/typescript/lib/typescript.d.ts" /> 
/// <reference path="../typings/browser.d.ts" /> 
/// <reference path="../typings/main.d.ts" /> 

brow SER:

/// <reference path="browser/ambient/body-parser/index.d.ts" /> 
/// <reference path="browser/ambient/express-serve-static-core/index.d.ts" /> 
/// <reference path="browser/ambient/express/index.d.ts" /> 
/// <reference path="browser/ambient/mime/index.d.ts" /> 
/// <reference path="browser/ambient/node/index.d.ts" /> 
/// <reference path="browser/ambient/serve-static/index.d.ts" /> 

主:

/// <reference path="main/ambient/body-parser/index.d.ts" /> 
/// <reference path="main/ambient/express-serve-static-core/index.d.ts" /> 
/// <reference path="main/ambient/express/index.d.ts" /> 
/// <reference path="main/ambient/mime/index.d.ts" /> 
/// <reference path="main/ambient/node/index.d.ts" /> 
/// <reference path="main/ambient/serve-static/index.d.ts" /> 
/// <reference path="main/mongoose/mongoose.d.ts" /> 

在我的项目,我呼吁refefences对文件的顶部:

/// <reference path="../_all.d.ts" /> 

import mongoose = require("mongoose"); 

export var userSchema = new mongoose.Schema({ 
    name: String 
}); 

export interface IUser extends mongoose.Document { 
    name: string; 
} 

export var repository = mongoose.model<IUser>("Userma"); 

我真的不知道,哪里是问题。代码没有其他错误(只有这个d.ts文件)。

你能帮助我吗,怎么了? 非常感谢!

回答

0

在你的_all.d.ts中,你不需要参考browser.d.ts,因为它们都包含相同的定义,因此你会看到重复的标识符错误。

/// <reference path="../node_modules/typescript/lib/typescript.d.ts" /> 
/// <reference path="../typings/main.d.ts" /> 
+0

是的,这是错误的评论。我只有这两条线。没有任何问题。 –

+0

很好,你解决了这个问题.. –

+0

我没有。但引用行不是问题。 –