WebStorm在使用SystemJS模块系统时从索引文件导入 [英] WebStorm to import from index file when using SystemJS module system

查看:123
本文介绍了WebStorm在使用SystemJS模块系统时从索引文件导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下源结构。

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

所有域文件都包含类似

export interface Car {
  someProperty: number;
}

索引文件如下所示

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

但是当自动导入WebStorm坚持导入这样的接口时

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

有没有办法让WebStorm更喜欢从索引文件导入?

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

推荐答案

您需要打开文件|设置|编辑|一般|自动导入设置并启用选项 [使用目录导入]

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

注意:需要 WebStorm 2016.3 或更高

这篇关于WebStorm在使用SystemJS模块系统时从索引文件导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆