我正在構建一個客戶端/服務器JS應用程序,並且使用Promises有一個大問題。它們要麼是未定義的,要麼是重複的,它似乎取決於@types包。Typescript typings - 重複名稱Promise /無法找到名字Promise
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) ✗
如果我刪除該程序包,然後我得到的客戶端錯誤:
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看起來是這樣的:
{
"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
}
}
這裏的顯示問題來來去去另一個版本
客戶端編譯罰款
➜ author git:(402-compile-errors) ✗ cd client
➜ client git:(402-compile-errors) ✗ tsc
➜ client git:(402-compile-errors) ✗ cd ../server
但服務器失敗
➜ server git:(402-compile-errors) ✗ 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:(402-compile-errors) ✗ rm -rf ../node_modules/@types/es6-promise
➜ server git:(402-compile-errors) ✗ tsc
➜ server git:(402-compile-errors) ✗ cd ../client
但現在客戶端無法
➜ 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) ✗
所以它似乎是一個catch22
難道unional的回答你的工作?你在哪裏添加了這個lib選項? –