typescript - WebStorm 2017.1 : TypeScript: import can be shortened inspection issue

标签 typescript webstorm

Inspection 正在提出这个问题......根据这个 WebStorm blog post ,我试图更新它,但它对这些导入提出了同样的问题:

server.ts

....
// models
import { IModel } from './models/model'; //import IModel
import { IUserModel } from './models/user'; //import IUserModel

模型/模型.ts

import { Model } from "mongoose";
import { IUserModel } from "./user";
export interface IModel {
  user: Model<IUserModel>;
}

models/user.ts

import { Document } from "mongoose";
import { IUser } from "../interfaces/user";
export interface IUserModel extends IUser, Document {
  //custom methods for user model would be defined here
}

已提供更新详情 in this post

dir/toExport.ts
    export class Foo {}
dir/index.ts
    export {Foo} from './toExport'
client.ts
    import {Foo} from './dir/toExport' //inspection warining

**after fix**
client.ts
    import {Foo} from './dir' 

但它并没有像它应该的那样工作......

更新

TypeScript 的 WebStorm 代码样式首选项

enter image description here

最佳答案

不幸的是,很多人不想默认使用 index.ts 导入目录(这是几个 EAP 的默认行为,但我们不得不禁用它)。

您可以在

中启用此行为

"File | Settings | Editor | Code Style | TypeScript | Imports" -> "Use directory import"

关于typescript - WebStorm 2017.1 : TypeScript: import can be shortened inspection issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43088021/

相关文章:

angular - 如何从 `.d.ts` 文件导入?

javascript - 选择不使用 Angular 2 绑定(bind)动态更新的选项

node.js - TypeScript:意外的保留字

javascript - WebStorm调试及后续点击

linux - 从 Ubuntu 中的程序保存后,文件所有权更改为 root

typescript - 如何解决/抑制 IntelliJ 警告,即模拟类未在任何 Angular 模块中声明?

Angular2 最终版本 - "Error: Angular requires Zone.js prolyfill"

typescript - TS2307 : Cannot find module 'class-validator'

typescript - 网络 Storm "Warning:File was not compiled because there is no a reference from tsconfig.json"

javascript - 使用 WebStorm 进行 React native 调试