我用gulp编译打字稿没有什么问题。我在我的tsconfig中设置了exclude目录,但是我得到* .d.ts错误:
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("."));
});
和来自Angular2的es5的tsconfig :
{
"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" />
浏览器:
/// <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 :(得分:0)
在_all.d.ts中,您不需要引用browser.d.ts,因为它们都包含相同的定义,因此您看到重复的标识符错误。
/// <reference path="../node_modules/typescript/lib/typescript.d.ts" />
/// <reference path="../typings/main.d.ts" />