gpt4 book ai didi

javascript - typescript :当 namespace 和类在库文件中具有相同名称时导入 namespace

转载 作者:行者123 更新时间:2023-11-30 13:55:10 25 4
gpt4 key购买 nike

我在从声明命名空间和同名类的文件导入命名空间时遇到问题。我可以访问类但不能访问命名空间。

来自docs ,我认为从导出合并命名空间和类的库中导入将为您提供来自两个声明的属性。但是,我只能从类中获取属性。

Namespaces are flexible enough to also merge with other types of declarations. To do so, the namespace declaration must follow the declaration it will merge with. The resulting declaration has properties of both declaration types. TypeScript uses this capability to model some of the patterns in JavaScript as well as other programming languages.

这是我的场景,

库文件:

class GoldenLayout {
}

namespace GoldenLayout {
export interface Config {
}
}

在我的项目中,我尝试使用Config 界面。我正在尝试以这种方式使用它,

import * as GoldenLayout from 'golden-layout';

const INITIAL_LAYOUT = GoldenLayout.Config = {
};

但是,我得到一个错误

Property 'Config' does not exist on type 'typeof GoldenLayout'.

我可以访问 GolderLayour 类中的属性和方法,但我不知道如何访问命名空间。

作为引用,我正在尝试使用这个 library在我的 Angular 8 应用中。

最佳答案

我认为你的问题是你没有定义配置而是双重分配。试试这个:

const INITIAL_LAYOUT: GoldenLayout.Config = { };

关于javascript - typescript :当 namespace 和类在库文件中具有相同名称时导入 namespace ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57437368/

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