动态更改typescript中的属性名称

动态更改typescript中的属性名称,typescript,class,properties,typing,Typescript,Class,Properties,Typing,我希望有一个类型(无需实现),它可以帮助我在类中添加一些动态字符串 例如: class Dog() { bark: () => void eat: () => void } // But actually in runtime, bark is nobark; eat is noeat // That's why I would like to have such type inteface Husky extends addSomethingInClass(Dog, 'n

我希望有一个类型(无需实现),它可以帮助我在类中添加一些动态字符串

例如:

class Dog() { 
  bark: () => void
  eat: () => void
}
// But actually in runtime, bark is nobark; eat is noeat
// That's why I would like to have such type
inteface Husky extends addSomethingInClass(Dog, 'no') {} 
// Husky.nobark && Husky.noeat can be autocompleted
inteface Corgi extends addSomethingInClass(Dog, 'go') {} 
// Corgi.gobark && Corgi.goeat can be autocompleted 
我不知道是否可以


感谢您的帮助

很遗憾,您必须使用一个装饰器才能在类型系统中进行这样的sting操作。您最好编写一个自定义工具(使用编译器API)来生成interfaces@Ken但是为什么呢?您想用它做什么?@mleko实际上我正在使用带名称空间选项的Vuex,并希望通过它让autocomplete调用该方法。$store.actions.bark。但是使用名称空间选项时,操作名称将是这个。$store.actions[{moduleName}/bark]。这就是为什么我想抄近路,在操作之前添加moduleName,以便在component@TitianCernicova-德拉戈米尔,我能要求一些例子吗?谢谢,这个听起来也不错