ค้นหาเว็บไซต์

typescript - ข้อผิดพลาด TS2300: ตัวระบุ 'RequestInfo' ซ้ำกัน


ฉันกำลังทำงานในโครงการ ReactXP ซึ่งฉันต้องใช้โมดูลเนทีฟของ React Native

ดังนั้นฉันจึงได้รวมประเภทของ react-native เป็นการพึ่งพาในโหมดนักพัฒนาแล้ว

โปรเจกต์ของฉันไม่สามารถคอมไพล์ได้ในขณะนี้พร้อมกับข้อผิดพลาดดังต่อไปนี้:

node_modules/@types/react-native/globals.d.ts(92,14): error TS2300: Duplicate identifier 'RequestInfo'.
node_modules/@types/react-native/index.d.ts(8751,11): error TS2451: Cannot redeclare block-scoped variable 'console'.
node_modules/@types/react-native/index.d.ts(8759,18): error TS2717: Subsequent property declarations must have the same type.  Property 'geolocation' must be of type 'Geolocation', but here has type 'GeolocationStatic'.
node_modules/@types/react-native/index.d.ts(8762,11): error TS2451: Cannot redeclare block-scoped variable 'navigator'.
node_modules/typescript/lib/lib.dom.d.ts(15764,13): error TS2451: Cannot redeclare block-scoped variable'navigator'.
node_modules/typescript/lib/lib.dom.d.ts(15940,13): error TS2451: Cannot redeclare block-scoped variable'console'.
node_modules/typescript/lib/lib.dom.d.ts(15997,6): error TS2300: Duplicate identifier 'RequestInfo'.
18:17:44 - Compilation complete. Watching for file changes.

ต่อไปนี้คือไฟล์ package.json ของฉัน:

"dependencies": {
        "react": "^16.4.0",
        "react-dom": "^16.3.1",
        "react-native": "^0.55.4",
        "react-native-windows": "^0.54.0",
        "reactxp": "^1.2.1"
    },
    "devDependencies": {
        "@types/react-native": "^0.55.16",
        "@types/webpack": "^4.1.3",
        "@types/node": "9.6.7",
        "@types/react-dom": "^16.0.5",
        "awesome-typescript-loader": "^5.0.0",
        "rnpm-plugin-windows": "^0.2.8",
        "source-map-loader": "^0.2.3",
        "ts-node": "^5.0.1",
        "tslint": "^5.9.1",
        "tslint-microsoft-contrib": "^5.0.3",
        "typescript": "^2.8.1",
        "webpack": "^4.5.0",
        "webpack-cli": "^2.0.13"
    }

และไฟล์ tsconfig.json

{
  "exclude": [
    "node_modules"
  ],
  "compilerOptions": {
    "declaration": false,
    "noResolve": false,
    "jsx": "react",
    "reactNamespace": "RX",
    "module": "commonjs",
    "target": "es5",
    "experimentalDecorators": true,
    "sourceMap": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "outDir": "./dist/",
    "types": [
      "lodash",
      "react",
      "react-dom"
    ],
    "lib": [
      "es6",
      "dom"
    ],
  },
  "include": [
    "./src/ts/**/*"
  ]
}

ฉันไม่เข้าใจว่าฉันทำผิดพลาดอะไร

ยินดีรับความช่วยเหลือทุกประเภท

คำตอบ #1

เพิ่ม "skipLibCheck": true ใน tsconfig.json

อ้างอิง: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/16825

คำตอบ #2

ฉันได้เพิ่ม "skipLibCheck": true และ "allowSyntheticDefaultImports": true ลงใน tsConfig.js แล้ว

บทความที่เกี่ยวข้อง