【发布时间】:2019-01-14 02:08:24
【问题描述】:
我有这个用于创建类型的枚举:
export enum MyTypeEnum {
one = 'one',
two = 'two',
three = 'three',
four = 'four'
}
export type MyTypeKeyFunctionValue = { [key in MyTypeEnum ]?: Function };
export type MyTypeKeyStringValue = { [key in MyTypeEnum ]?: string };
我有一个包含使用这些确切键的 getter 的类:
export class MyClass {
get one() { ... implementation ...}
get two() { ... implementation ...}
get three() { ... implementation ...}
get four() { ... implementation ...}
}
我想知道是否有办法创建一个接口,该接口在实现时会强制类具有这些 getter。
我试过了
interface IClass{
[key in MyTypeEnum ] : Function
}
但它不起作用。这可能吗?
【问题讨论】:
标签: typescript