gpt4 book ai didi

angular - VS Code 修复库的导入路径

转载 作者:行者123 更新时间:2023-12-05 06:51:07 25 4
gpt4 key购买 nike

我创建了一个简单的 Angular 库(打包并发布到公司内部的 npm 存储库)。在我的库中,我还导出了库组件中使用的模型,例如:

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

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

然后,为了导出它们,我将它们包含在 index.ts 中,如下所示:

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

现在的问题是,一旦我想在常规项目(我安装了这个包的地方)中使用任何模型,Visual Studio Code 会建议两个不同的模型导入路径,如图所示: enter image description here

问题是,如果我选择第二个选项(较长的一个), Angular 编译器会失败并说它无法解析我的模型(即使路径是正确的)。如果我想成功使用这个项目,我必须使用第一个链接。

现在我的问题是,如何更改 index.ts 文件,以便只有一个导入路径(正确的路径)会出现在使用我的包的人的 Visual Studio 代码中?

最佳答案

你可以在 .vscode/settings.json 中添加一些东西来实现以下效果:

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

关于angular - VS Code 修复库的导入路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66262312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com