WebStorm to import from index file when using SystemJS module system

人盡茶涼 提交于 2019-12-08 19:51:18

问题


Suppose I have the following source structure.

/home
  home.component.ts
/shared
  /domain
    car.domain.ts
    house.domain.ts
    person.domain.ts
    index.ts

All the domain files contains something like

export interface Car {
  someProperty: number;
}

The index file looks like this

export * from './car.domain';
export * from './house.domain';
export * from './person.domain';

Then in works perfectly fine to import like this in my home component.

import { Car, Person } from '../shared/domain';

or

import { Car, Person } from '../shared/domain/index';

But when auto-importing WebStorm insists on importing the interfaces like this

import { Car } from '../shared/domain/car.domain';
import { Person } from '../shared/domain/person.domain';

Is there any way to have WebStorm to prefer to import from the index file?


回答1:


You need to open File | Settings | Editor | General | Auto Import settings and enable the option [Use directory import]

Note: requires WebStorm 2016.3 or higher



来源:https://stackoverflow.com/questions/40634610/webstorm-to-import-from-index-file-when-using-systemjs-module-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!