In my TypeScript project, I prefer to use an index.ts that can define exports from all my modules in a proper order for the code to work. Part of such a file looks something like this:
// from index.ts
export * from "../common/index";
export * from "./DomTools";
export * from "./ClientUserSession";
export * from "./ClientGameSession";
export * from "./LibraryManager";
export * from "./RichTextEditor";
export * from "./Binding";
export * from "./StyleSheetManager";
export * from "./ViewBinder";
...
In a given code file, I may have the following:
// from DummyClass.ts
import {
GameState, // Comes from ../common/GameState.ts
ViewBinder, // Comes from ./ViewBinder.ts
} from "./index". // this could also be from "."
export class DummyClass {
// NOTE: ClientGameSession must be imported...
public constructor(public readonly gameSession: ClientGameSession){}
}
If I simply type this portion of the code: ClientGameSession)
, VSCode will automatically add this line to the header of the file:
import { ClientGameSession } from "./ClientGameSession";
However, if I reject that (undo) and instead get quick-fix suggestions from VSCode, it will offer to update import from "./index"
. Selecting that option puts the import where I want it:
import {
GameState, // Comes from ../common/GameState.ts
ViewBinder, // Comes from ./ViewBinder.ts
ClientGameSession, // >>> THIS is what I prefer
} from "./index". // this could also be from "."
So the obvious question is:
Can I configure VSCode so that when it automatically adds an import as I type, it uses what is essentially the first suggestion I would get in a quick-fix list (i.e., it would add the import to an existing "./index" import list) rather than adding a new import from the original code file for the item in question?
Thanks!