VS Code fix import path(s) for library

Viewed 108

I have created a simple Angular library (that is packaged and published to internal company's npm repository). Here in my library I have also exported models which are used within library's components such as the following:

export class AdsToolbarMenuItem {
    iconName: string;
    label: string;
    enabled: boolean = true;
    menuAction: () => void;

    constructor(init?: Partial<AdsToolbarMenuItem>) {
        Object.assign(this, init);
    }
}

Then, in order to export them, I have included them in index.ts as following:

export * from './lib/angular-components.module';
export * from './lib/models/AdsToolbarMenuItem';
export * from './lib/models/AdsToolbarMainActionItem';
export * from './lib/models/ContactBox';

now the problem is, once I want to use any of the models in regular project (where I have installed this package), that Visual Studio Code suggests two different import paths for the model as visible on the image: enter image description here

The problem is, that if I select the second option (longer one), angular compiler fails and says that it cannot resolve my model (even though the path is correct). If I want to succesfully use this project, I have to use the first link.

Now my question is, how can I change the index.ts file the way, so that only one import path (the correct one) will appear in Visual Studio code for people using my package?

1 Answers

You can add something to the following effect, to .vscode/settings.json:

{
    "typescript.preferences.autoImportFileExcludePatterns": [
        "@ads-shared/ads.shared.angular/lib*"
    ]
}
Related