如何键入枚举和对象具有相同的属性反应打字稿
我有一个枚举:
enum INFO_CODES {
goToInit = 'goToInit',
lockIp = 'lockIp',
}
,我想创建一个具有相同属性(仅gotoinit和lockip)的对象(或枚举)
const SOME_OBJ = {
goToInit: function, //here i need function
lockIp: function,//here i need function
someProp:function //here i need mistake,can create only like in
INFO_CODES props.
}
i have an enum:
enum INFO_CODES {
goToInit = 'goToInit',
lockIp = 'lockIp',
}
and i want to create an object(or enum also) with the same properties (only goToInit and lockIp)
const SOME_OBJ = {
goToInit: function, //here i need function
lockIp: function,//here i need function
someProp:function //here i need mistake,can create only like in
INFO_CODES props.
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用并只需使用
enum
作为密钥的第一个通用参数,然后将您要具有下一步的任何功能类型。You can use a
Record
and just use theenum
as the first generic parameter for the key and then whatever function type you want to have next.