如何在单个打字稿文件中声明多个枚举并在单个导出语句下返回(以免直接揭露单个枚举)
我想在同一文件中有多个枚举,并在单个导出
语句中导出它们。当i 导入
在另一个文件中此文件时,我可以根据需要访问任何特定的枚举。
我当前拥有的内容:2 Secleate .ts
动作和组枚举的文件,
first .ts file:
export enum Actions {
Delete: "Delete",
Update: "Update"
}
second .ts file:
export enum Groups {
Lead: "Lead",
Permanent: "Permanent"
}
预期:我想要一个.ts
文件和单个导出
语句。使用此导出
,我可以访问我的两个枚举。 类似:enums.actions或enums.groups
。
组,只能通过枚举或枚举访问操作。其他一些文件应该无法直接访问单个枚举。
建议这样做的建议是什么?
I want to have multiple enums in the same file and export them under single export
statement. and when I import
this single file in another file, I can access any particular enum as required.
What I current have: 2 seperate .ts
file for Actions and Groups enums,
First .ts file:
export enum Actions {
Delete: "Delete",
Update: "Update"
}
Second .ts file:
export enum Groups {
Lead: "Lead",
Permanent: "Permanent"
}
Expected: I want a single .ts
file and a single export
statement. Using this export
, I can access my both the enums. something like: Enums.Actions or Enums.Groups
.
Groups, Actions should only be accessed by Enums.Actions or Enums.Groups? some other file should not be able to access individual enums directly.
What is the suggested way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样做:
如何在文件中使用:
我们可以使用
enum.actions
和enum.groups
访问。将枚举封装在命名空间
中,允许操作和组不直接从外部访问。you can do it like this:
How to use in a file:
We can access using
Enum.Actions
andEnum.Groups
. Encapsulating enums in anamespace
, allows Actions and Groups to not directly get accessed from outside.