带有动态键的Typescript通用接口

带有动态键的Typescript通用接口,typescript,typescript-generics,Typescript,Typescript Generics,嘿,TS中可能存在以下情况 警告:出现极端伪代码! 接口MyInterface{ ${T}_函数:(a:number):void; ${T}_prop:number; } MyClass实现了MyInterface{ //上帝说: //您需要实施: //->类型编号和 //->带有签名的示例函数(a:数字):void; } 如果可能,用例如下所示: MyClass implements MyInterface<'cat'>, MyInterface<'dog'> {

嘿,TS中可能存在以下情况

警告:出现极端伪代码!
接口MyInterface{
${T}_函数:(a:number):void;
${T}_prop:number;
}
MyClass实现了MyInterface{
//上帝说:
//您需要实施:
//->类型编号和
//->带有签名的示例函数(a:数字):void;
}
如果可能,用例如下所示:

MyClass implements MyInterface<'cat'>, MyInterface<'dog'> {
   I know I have to implement 4 function with specific name.
}
MyClass实现MyInterface,MyInterface{
我知道我必须用特定的名称实现4个函数。
}

好,这就是问题所在。你不需要总是一个字符串。不仅如此,它还必须是特定的单个字符串。例如,不允许使用
MyInterface
<代码>我的接口也将不被允许。这是如此疯狂的具体,它真的尖叫我很高兴有一个变通办法。这个预udocode只是解释了im所追求的。直到用TypeScript实现为止,我认为这是不可能的。
MyClass implements MyInterface<'cat'>, MyInterface<'dog'> {
   I know I have to implement 4 function with specific name.
}