gpt4 book ai didi

angular - 如何在 Spartacus 2.1 中使用类型增强?

转载 作者:行者123 更新时间:2023-12-04 03:39:03 24 4
gpt4 key购买 nike

关于模块/类型增强的 spartacus 文档说它在 spartacus 2.1 中受支持。 https://sap.github.io/spartacus-docs/type-augmentation/#page-title

但是当我尝试扩展 ConsentTemplate 接口(interface)时

import { ConsentTemplate } from '@spartacus/core';

declare module '@spartacus/core' {
interface ConsentTemplate {
documentUrl?: string;
}
}

我收到此错误 => 错误 TS2339:“ConsentTemplate”类型上不存在属性“documentUrl”。

是否可以在 Spartacus 2.1 中使用类型增强?如果是这样,如何让它发挥作用?

最佳答案

Spartacus 2.1 支持类型增强。我在我的 app.module.ts 中测试了它。

enter image description here

然后在我的应用程序代码中,我可以从 Visual Studio Code 字段自动完成列表中看到新的扩展字段“documentUrl”,并将其用作其他标准字段。 enter image description here

关于angular - 如何在 Spartacus 2.1 中使用类型增强?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66384788/

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