ezain
ezain

Reputation: 1485

IntelliJ don't recognize Promise type in a basic Ionic2 project

I am developing an Ionic 2 rc.1 app and I use idea intelliJ 2016.2.4.

Project runs fine but the IDE don't recognize the typescript definition of Promise because it seems the type "is not included in tsconfig.json'

The inspection error is: Corresponding file is not included in tsconfig.json

my tsconfig.json look like that:

{
    "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
  }
}

if I remove node_modules from the "exclude" block then I do not have problem with the IDE inspection but the project run ionic serve fails in the lint phase.

here is my 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"
  ]
}

Someone knows how to solve this problem?

Thanks

Upvotes: 8

Views: 2237

Answers (4)

ezain
ezain

Reputation: 1485

Finally I have solved my problem with a workaround.

That solves the problems with all not recognized es2015 types into IDE:

Prerequisite: upgrade Idea IntelliJ to >2016.2.4

  1. First make sure that typescript is installed as global.

npm install -g typescript 2. Set in the settings the typescript version installed above

In Preferences > Languages & Frameworks > TypeScript > TypeScript version > Edit

Set the path to npm package. In my case: /usr/local/lib/node_modules/typescript/lib

  1. Finally in the compiler options put on the option Set options manually instance of Use tsconfig.json

  2. In some cases you should active the option Use TypeScript Service(Experimental)

Autocompletions works and no more problems with the inspector.

Upvotes: 7

Tom
Tom

Reputation: 5121

I resolved this by installing typescript globally at the version of typescript in the project

Upvotes: 0

mike.adc
mike.adc

Reputation: 311

I solved it adding es6 to lib section in tsconfig.json:

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

Hope this helps.

Upvotes: 3

cither
cither

Reputation: 313

I installed @types/es6-shim via npm and deleted lib option from tsconfig.json. And it is working on PhpStorm 2016.2.2.

Upvotes: 0

Related Questions