WebStorm 2017.1: TypeScript: import can be shortened inspection issue
Asked Answered
C

2

6

Inspection is raising this issue... according to this WebStorm blog post, I tried to update it but it's raising the same issue for these imports:

server.ts

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

models/model.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
}

details for update are given 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' 

but it does not work as it should do ...

UPDATE

WebStorm Code Style preferences for TypeScript

enter image description here

Calliecalligraphy answered 29/3, 2017 at 8:16 Comment(1)
R
3

Unfortunately there are a lot of people which don't want to import directories with index.ts by default (it was the default behaviour several EAPs but we had to disable it).

You can enable this behaviour in

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

Rudolph answered 29/3, 2017 at 13:4 Comment(4)
Thanks for feedback... I did it (Webstorm 2017-1) but the warning I. still there ... I updated my question with pref snapshotCalliecalligraphy
@erwin you don't need 'use path relative to tsconfig.json' settingRudolph
Yeah, I don't understand this- and I don't even understand what the inspection warning means... how can it be shortened...? No it can't- not as far as I can see. And nope, changing that setting doesn't make phpStorm shut up about it either :/Offering
I can confirm the warning still does not go away on WebStorm 2023.1, no matter whether "Use directory import" is checked or not. I want to always use relative paths while in the same module, even if they are longer than the aliased paths we use for cross-module imports.Biggin
B
0

I know this is a really old question, but I thought I would post this here in case it helps anyone else searching for how to disable this annoying warning.

"File | Settings | Editor | Inspections | JavaScript and TypeScript | General" -> untick "Import can be shortened"

Screenshot

Barrier answered 9/10 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.