gpt4 book ai didi

javascript - 使用枚举作为类型/接口(interface)

转载 作者:搜寻专家 更新时间:2023-10-30 21:20:25 29 4
gpt4 key购买 nike

在将枚举器从 JavaScript 转换为 TypeScript 时,我必须添加自己的枚举 - myEnumType

如果我使用这样的枚举作为属性类型:

prop:myEnumType

预计该值必须是 myEnumType 类型。

我们如何在 TypeScript 中声明一个属性,将枚举本身表示为一种类型,而不是该类型的值?

我正在尝试通过接口(interface)属性将枚举公开为一种类型。

最佳答案

I'm trying to expose the enum as a type, via an interface property.

您可以声明一个枚举,例如在 vendor.d.ts 中:

declare enum MyEnumType {
Member1,
Member2,
}

更新

And how would I then declare a property of the enum as a type, via an interface property?

interface Foo {
prop: MyEnumType
}

关于javascript - 使用枚举作为类型/接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36298438/

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