Angularjs 错误TS2300:重复标识符';要求';在TypeScript编译过程中
我正在angular项目中编译所有TypeScript,但我得到了一个众所周知的错误:Angularjs 错误TS2300:重复标识符';要求';在TypeScript编译过程中,angularjs,typescript,typescript1.8,Angularjs,Typescript,Typescript1.8,我正在angular项目中编译所有TypeScript,但我得到了一个众所周知的错误: error TS2300: Duplicate identifier 'require'. 但是,大多数有此问题的人都会遇到此问题,因为他们有两个导致复制错误的文件。在我的例子中,这是因为“require”一词在同一个文件中被使用了两次 /typings/globals/angular/index.d.ts(1707,9): 及 它是从dt源提取的默认角度键入定义文件 我有本地和全局的TypeScrip
error TS2300: Duplicate identifier 'require'.
但是,大多数有此问题的人都会遇到此问题,因为他们有两个导致复制错误的文件。在我的例子中,这是因为“require”一词在同一个文件中被使用了两次
/typings/globals/angular/index.d.ts(1707,9):
及
它是从dt源提取的默认角度键入定义文件
我有本地和全局的TypeScript。我试图删除本地副本,但失败了。这是我的tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"files": [
"typings/index.d.ts"
]
}
还有my typings.json:
{
"globalDependencies": {
"angular": "registry:dt/angular#1.5.0+20160627014139",
"bootstrap": "registry:dt/bootstrap#3.3.5+20160619023404",
"jquery": "registry:dt/jquery#1.10.0+20160620094458"
}
}
最后是我的主要索引d.ts:
/// <reference path="globals/angular/index.d.ts" />
/// <reference path="globals/bootstrap/index.d.ts" />
/// <reference path="globals/jquery/index.d.ts" />
//
///
///
您不应该在tsconfig.json
文件的files
部分列出d.ts
文件。这是您列出需要转换为javascript的已编写文件的位置。您看到的问题是由于transpiler试图将typings/index.d.ts
文件转换为javascript而导致的,而它不应该这样做。键入定义实际上只是为了让代码编辑器能够提供类型提示、警告错误以及完成代码
看一看
/// <reference path="globals/angular/index.d.ts" />
/// <reference path="globals/bootstrap/index.d.ts" />
/// <reference path="globals/jquery/index.d.ts" />