在同一接口中访问接口属性值
我想知道是否可以在同一接口声明中访问接口Prop值,以动态设置类型。
我正在尝试做这样的事情:
export type MethodNames = "IsFallmanagerUpdateAllowed" | "UpdateStammFallmanager";
export interface IsFallmanagerUpdateAllowed {
plcParameter : StammFallmanagerParameter
}
export interface UpdateStammFallmanager {
plcParameter : StammFallmanagerParameter
}
export interface ServerTaskParam<T> extends system.ServerTaskParam<T> {
name : `${Class.NAME}`,
methodName : MethodNames,
paramObj : // here depending on the passed methodname type should be IsFallmanagerUpdateAllowed or UpdateStammFallmanager
// paramObj : T -> this is what I use atm but I want to make it more dynamic
}
请注意,可能有更多MethodNames
。
我要实现的是,当传递名称和方法名称时,Intellisense应该能够直接告诉我应以paramobj
的方式传递哪种类型的对象。
如果可能的话,应该是这样的:
export interface ServerTaskParam extends system.ServerTaskParam {
name : `${Class.NAME}`,
methodName : MethodNames,
paramObj : [ methodName ] -> use methodName value to refer to one or the other interface in the same namespace (pseudo syntax)
}
我现在正在搜索网络一段时间,但找不到任何东西。这甚至可能吗?
I'm wondering if it's possible to access an interface prop value in the same interface declaration in order to set the types dynamically.
I'm trying to do something like this:
export type MethodNames = "IsFallmanagerUpdateAllowed" | "UpdateStammFallmanager";
export interface IsFallmanagerUpdateAllowed {
plcParameter : StammFallmanagerParameter
}
export interface UpdateStammFallmanager {
plcParameter : StammFallmanagerParameter
}
export interface ServerTaskParam<T> extends system.ServerTaskParam<T> {
name : `${Class.NAME}`,
methodName : MethodNames,
paramObj : // here depending on the passed methodname type should be IsFallmanagerUpdateAllowed or UpdateStammFallmanager
// paramObj : T -> this is what I use atm but I want to make it more dynamic
}
Note that there could be more MethodNames
.
What I want to achieve is that when passing name and methodName the intellisense should be able to tell me directly which type of object should be passed as paramObj
.
It should be something like this if possible:
export interface ServerTaskParam extends system.ServerTaskParam {
name : `${Class.NAME}`,
methodName : MethodNames,
paramObj : [ methodName ] -> use methodName value to refer to one or the other interface in the same namespace (pseudo syntax)
}
I'm searching the net for a while now but couldn't find anything. Is this even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
I think what you need is just a union:
I think what you need is just a union:
Playground
您可以创建一个包含所有可能接口的复合类型,因此您可以使用此键使用此“更高类型”:
You could create a composite type holding every possible interface so you can use this "higher type" with its keys like so: