具有动态键的Typescript通用接口

时间:2019-09-04 15:52:21

标签: typescript typescript-generics

嘿,TS中有以下可能吗?

警告:极端伪代码传入!

interface MyInterface<T> {
    ${T}_function: (a: number): void;
    ${T}_prop: number;
}

MyClass implements MyInterface<'Example'> {
    // TSLINT-GOD says:
    // You need to implement: 
    // -> Example_prop of type number and
    // -> Example_function with signature (a: number): void;
}

如果可能的话,用例如下:

MyClass implements MyInterface<'cat'>, MyInterface<'dog'> {
   I know I have to implement 4 function with specific name.
}

0 个答案:

没有答案