Javascript Typescript打字-重复名称承诺/找不到名称承诺

Javascript Typescript打字-重复名称承诺/找不到名称承诺,javascript,typescript,promise,typescript-typings,Javascript,Typescript,Promise,Typescript Typings,我正在构建一个客户端/服务器JS应用程序,在使用Promises时遇到了一个大问题。它们要么是未定义的,要么是重复的,这似乎取决于@types包 npm install --save @types/es6-promise` 这将导致如下服务器错误: cd ../server ➜ server git:(master) ✗ tsc ../node_modules/@types/es6-promise/index.d.ts(11,15): error TS2300: Duplicate ide

我正在构建一个客户端/服务器JS应用程序,在使用Promises时遇到了一个大问题。它们要么是未定义的,要么是重复的,这似乎取决于@types包

npm install --save @types/es6-promise`
这将导致如下服务器错误:

cd ../server 
➜  server git:(master) ✗ tsc
../node_modules/@types/es6-promise/index.d.ts(11,15): error TS2300: Duplicate identifier 'Promise'.
../node_modules/@types/es6-promise/index.d.ts(42,19): error TS2300: Duplicate identifier 'Promise'
.../../../../../../../usr/local/lib/node_modules/typescript/lib/lib.es6.d.ts(4936,11): error TS2300: Duplicate identifier 'Promise'.
../../../../../../../usr/local/lib/node_modules/typescript/lib/lib.es6.d.ts(5261,11): error TS2300: Duplicate identifier 'Promise'.
../../../../../../../usr/local/lib/node_modules/typescript/lib/lib.es6.d.ts(5511,13): error TS2300: Duplicate identifier 'Promise'.
../../../../../../../usr/local/lib/node_modules/typescript/lib/lib.es6.d.ts(5737,11): error TS2300: Duplicate identifier 'Promise'.
➜  server git:(master) ✗ 
{
    "compilerOptions": {
        "sourceMap": true,
        "noImplicitAny": false,
        "target": "es6",
        "jsx": "react",
        "module": "commonjs",
        "moduleResolution": "node",
        "isolatedModules": false,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declaration": false,
        "removeComments": true,
        "noLib": false,
        "preserveConstEnums": true,
        "suppressImplicitAnyIndexErrors": true,
        "noUnusedLocals": true
    },
    "filesGlob": [
        "**/*.ts",
        "**/*.tsx",
        "**/*.tsd"
    ],
    "compileOnSave": true,
    "buildOnSave": false,
    "atom": {
        "rewriteTsconfig": false
    }
}
如果删除该包,则会出现客户端错误:

tsc
src/components/GeneralChatAdminInputArea.tsx(100,14): error TS2304: Cannot find name 'Promise'.
src/components/GeneralChatAdminInputArea.tsx(103,16): error TS2304: Cannot find name 'Promise'.
src/routes/users/index.ts(11,21): error TS2304: Cannot find name 'Promise'.
src/routes/users/index.ts(12,21): error TS2304: Cannot find name 'Promise'.
src/routes/users/index.ts(13,3): error TS2304: Cannot find name 'Promise'.
有什么出路

我的tsconfig.json如下所示:

cd ../server 
➜  server git:(master) ✗ tsc
../node_modules/@types/es6-promise/index.d.ts(11,15): error TS2300: Duplicate identifier 'Promise'.
../node_modules/@types/es6-promise/index.d.ts(42,19): error TS2300: Duplicate identifier 'Promise'
.../../../../../../../usr/local/lib/node_modules/typescript/lib/lib.es6.d.ts(4936,11): error TS2300: Duplicate identifier 'Promise'.
../../../../../../../usr/local/lib/node_modules/typescript/lib/lib.es6.d.ts(5261,11): error TS2300: Duplicate identifier 'Promise'.
../../../../../../../usr/local/lib/node_modules/typescript/lib/lib.es6.d.ts(5511,13): error TS2300: Duplicate identifier 'Promise'.
../../../../../../../usr/local/lib/node_modules/typescript/lib/lib.es6.d.ts(5737,11): error TS2300: Duplicate identifier 'Promise'.
➜  server git:(master) ✗ 
{
    "compilerOptions": {
        "sourceMap": true,
        "noImplicitAny": false,
        "target": "es6",
        "jsx": "react",
        "module": "commonjs",
        "moduleResolution": "node",
        "isolatedModules": false,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declaration": false,
        "removeComments": true,
        "noLib": false,
        "preserveConstEnums": true,
        "suppressImplicitAnyIndexErrors": true,
        "noUnusedLocals": true
    },
    "filesGlob": [
        "**/*.ts",
        "**/*.tsx",
        "**/*.tsd"
    ],
    "compileOnSave": true,
    "buildOnSave": false,
    "atom": {
        "rewriteTsconfig": false
    }
}
这是另一个版本,显示了问题的来龙去脉

客户编译得很好 但服务器出现故障 删除库,现在服务器将编译 但现在客户端失败了
因此,您的
tsconfig.json
中似乎缺少
lib
,这似乎是一个catch22

// tsconfig.json
{
  "compilerOptions": {
    "lib": [
      "es2015"
    ]
  }
}

即使我的目标是es6?这到底是从哪里来的?我也有单独的客户端和服务器的tsconfig,这个咒语应该去哪里?我已经尝试过了,得到了
错误TS5023:未知的编译器选项“lib”。
这是用
tsc 1.5.3
更新你的tsc。现在是2.2Did unional为您解答的问题?您必须在哪里添加lib选项?
➜  client git:(402-compile-errors) ✗ tsc
src/components/GeneralChatAdminInputArea.tsx(100,14): error TS2304: Cannot find name 'Promise'.
src/components/GeneralChatAdminInputArea.tsx(103,16): error TS2304: Cannot find name 'Promise'.
src/routes/users/index.ts(11,21): error TS2304: Cannot find name 'Promise'.
src/routes/users/index.ts(12,21): error TS2304: Cannot find name 'Promise'.
src/routes/users/index.ts(13,3): error TS2304: Cannot find name 'Promise'.
➜  client git:(402-compile-errors) ✗ 
// tsconfig.json
{
  "compilerOptions": {
    "lib": [
      "es2015"
    ]
  }
}