Hampus Hampus - 1 year ago 187
TypeScript Question

WebStorm to import from index file when using SystemJS module system

Suppose I have the following source structure.


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';


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?

Answer Source

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

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download