【问题标题】:Typescript Error Subsequent variable declarations must have the same type打字稿错误后续变量声明必须具有相同的类型
【发布时间】:2020-01-03 10:05:35
【问题描述】:

打字稿错误

随后的变量声明必须具有相同的类型。多变的 'driver' 必须是 'string | string[]',但这里有类型 '字符串 | LocalForageDriver | LocalForageDriver[]'。

随后的变量声明必须具有相同的类型。多变的 'version' 必须是 'number' 类型,但这里有 'string' 类型。

package.json

{
  "name": "Test",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "2.4.8",
    "@angular/compiler": "2.4.8",
    "@angular/compiler-cli": "2.4.8",
    "@angular/core": "2.4.8",
    "@angular/forms": "2.4.8",
    "@angular/http": "2.4.8",
    "@angular/platform-browser": "2.4.8",
    "@angular/platform-browser-dynamic": "2.4.8",
    "@angular/platform-server": "2.4.8",
    "@ionic-native/core": "^3.1.1",
    "@ionic-native/in-app-browser": "^3.1.1",
    "@ionic/storage": "^1.1.7",
    "ionic-angular": "2.2.0",
    "ionic-native": "^2.4.1",
    "ionicons": "^3.0.0",
    "localforage": "^1.7.3",
    "localforage-cordovasqlitedriver": "^1.8.0",
    "node-sass": "^4.12.0",
    "rxjs": "5.0.1",
    "sw-toolbox": "^3.4.0",
    "zone.js": "0.7.2"
  },
  "devDependencies": {
    "@ionic/app-scripts": "^1.1.3",
    "typescript": "^2.0.9"
  },
  "cordovaPlugins": [
    "cordova-plugin-splashscreen",
    "cordova-plugin-whitelist",
    "cordova-plugin-console",
    "cordova-plugin-statusbar",
    "cordova-plugin-device",
    "ionic-plugin-keyboard",
    "cordova-plugin-nativestorage",
    "cordova-plugin-inappbrowser"
  ],
  "cordovaPlatforms": [
    "ios",
    {
      "platform": "ios",
      "version": "",
      "locator": "ios"
    }
  ],
  "description": "appture2: An Ionic project"
}

随后的变量声明必须具有相同的类型。多变的 '_support' 必须是 'boolean | LocalForageDriverSupportFunc', 但这里有类型'boolean |承诺”。

【问题讨论】:

    标签: typescript ionic-framework ionic2 localforage


    【解决方案1】:

    从你的 package.json 我可以看到你设置了

    "cordovaPlatforms": [
        "ios",
        {
          "platform": "ios",
          "version": "", //< -- string
          "locator": "ios"
        }
      ],
    

    试试这个:

    "cordovaPlatforms": [
        "ios",
        {
          "platform": "ios",
          "version": 1, //<--set as number
          "locator": "ios"
        }
      ],
    

    希望对你有帮助!

    【讨论】:

    • 它在 ionic serve node_modules/@types/localforage/index.d.ts 文件上出现错误
    • 尝试删除你的 node_modules .folder .. 然后尝试 npm ci
    • 更改@ionic/storage 2.0版解决了这个问题。
    猜你喜欢
    • 2016-11-07
    • 2019-09-04
    • 1970-01-01
    • 2017-11-15
    • 2018-04-18
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 2018-01-10
    相关资源
    最近更新 更多