【问题标题】:IntelliJ don't recognize Promise type in a basic Ionic2 projectIntelliJ 无法识别基本 Ionic2 项目中的 Promise 类型
【发布时间】:2017-03-02 11:27:21
【问题描述】:

我正在开发一个 Ionic 2 rc.1 应用程序,我使用 idea intelliJ 2016.2.4。

项目运行良好,但 IDE 无法识别 Promise 的 typescript 定义,因为该类型似乎“未包含在 tsconfig.json 中”

检查错误为:Corresponding file is not included in tsconfig.json

我的 tsconfig.json 看起来像这样:

{
    "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "target": "es5"
  },
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

如果我从“排除”块中删除 node_modules,那么我的 IDE 检查没有问题,但项目运行 ionic serve 在 lint 阶段失败。

这是我的 package.json

{
  "name": "ionic-hello-world",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "build": "ionic-app-scripts build",
    "watch": "ionic-app-scripts watch",
    "serve:before": "watch",
    "emulate:before": "build",
    "deploy:before": "build",
    "build:before": "build",
    "run:before": "build"
  },
  "dependencies": {
    "@angular/common": "^2.0.0",
    "@angular/compiler": "^2.0.0",
    "@angular/compiler-cli": "0.6.2",
    "@angular/core": "^2.0.0",
    "@angular/forms": "^2.0.0",
    "@angular/http": "^2.0.0",
    "@angular/platform-browser": "^2.0.0",
    "@angular/platform-browser-dynamic": "^2.0.0",
    "@angular/platform-server": "^2.0.0",
    "@ionic/storage": "^1.0.3",
    "ionic-angular": "^2.0.0-rc.1",
    "ionic-native": "^2.2.3",
    "ionicons": "^3.0.0",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "^0.6.21"
  },
  "devDependencies": {
    "@ionic/app-scripts": "^0.0.36",
    "typescript": "^2.0.3"
  },
  "cordovaPlugins": [
    "cordova-plugin-device",
    "cordova-plugin-console",
    "cordova-plugin-whitelist",
    "cordova-plugin-splashscreen",
    "cordova-plugin-statusbar",
    "ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": [
    "ios@4.2.1",
    "android@5.2.2"
  ]
}

有人知道如何解决这个问题吗?

谢谢

【问题讨论】:

  • 您是否尝试过运行 typings install 命令?
  • 嗨@DanielSuchý。 Ionic rc-1 中不再有 typings.json,现在它与 npm @types 一起使用
  • 安装一个promise @types 包,如es6-promisecore-js(假设Ionic 安装不这样做,您可以查看@types 文件夹以确保) .安装完成后,将typeRoots: [ "node_modules/@types"] 添加到您的 tsconfig 文件中,让它获取类型定义

标签: intellij-idea typescript ionic2


【解决方案1】:

我终于用一种变通方法解决了我的问题。

这解决了所有无法识别的 es2015 类型进入 IDE 的问题:

先决条件:将Idea IntelliJ升级到>2016.2.4

  1. 首先确保 typescript 安装为全局。

npm install -g typescript 2.在设置中设置上面安装的打字稿版本

在首选项 > 语言和框架 > TypeScript > TypeScript 版本 > 编辑中

设置 npm 包的路径。就我而言:/usr/local/lib/node_modules/typescript/lib

  1. 最后在编译选项上放上选项设置选项 手动 使用tsconfig.json的实例

  2. 在某些情况下,您应该激活选项使用 TypeScript 服务(实验)

自动完成功能有效,检查员不再有问题。

【讨论】:

    【解决方案2】:

    我通过在项目中的 typescript 版本全局安装 typescript 解决了这个问题

    【讨论】:

      【解决方案3】:

      我解决了它在tsconfig.json 中添加es6lib 部分:

      "lib": [
        "es2016",
        "dom",
        "es6" // added
      ]
      

      希望这会有所帮助。

      【讨论】:

        【解决方案4】:

        我通过 npm 安装了@types/es6-shim,并从tsconfig.json 中删除了lib 选项。它正在 PhpStorm 2016.2.2 上运行。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-01-12
          • 1970-01-01
          • 2019-09-18
          • 2023-01-18
          相关资源
          最近更新 更多