Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improving the imports in Webstorm 11 using JSPM and Typescript

I am using JSPM and Typescript for an Angular2 project and Webstorm 11 seems confused about the import paths of the TS classes.

enter image description here

The first import is the correct one:

import {Component} from "angular2/core";

But the other two are referencing directly from the jspm_packages folder importing this two paths incorectly:

import {Component} from "../../jspm_packages/npm/[email protected]/src/core/metadata";
import {Component} from "../../jspm_packages/npm/[email protected]/ts/src/core/metadata";

I have ignored both node_modules and jspm_packages in tsconfig.json as Webstorm seems to recognize it, but no luck so far.

Is there any way i can configure Webstorm to automatically import the correct module and ignore the other two?

like image 711
korun Avatar asked Jan 05 '16 13:01

korun


People also ask

Is WebStorm good for TypeScript?

With WebStorm, you can run and debug client-side TypeScript code and TypeScript code running in Node. js. Learn more from Running and debugging TypeScript.

How do I sort imports in WebStorm?

If we want to go a step further and sort the imports, we can go to Preferences / Settings | Editor | Code Style | JavaScript or TypeScript and select Sort imports by modules on the Imports tab.

How do you auto import on WebStorm?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | General | Auto Import. On the Auto Import page that opens, use the checkboxes in the TypeScript/JavaScript area to enable or disable import generation on code completion.

What is optimize import?

Quickly remove any unused imports and more. With the Optimize imports action (Ctrl+Alt+O), you can quickly remove any unused imports, merge imports from the same module, and optionally sort the import statements.


1 Answers

jspm is currently not supported by Webstorm. But node.js is. If you install angular2 via npm the imports work:

npm i [email protected] es6-promise@^3.0.2 es6-shim@^0.33.3 [email protected] [email protected] [email protected] --save

like image 86
sod Avatar answered Sep 21 '22 17:09

sod