【发布时间】:2018-09-05 13:46:46
【问题描述】:
假设我有一个这样的界面MyInterface:
interface MyInterface = {
param1: string;
param2: number;
}
有没有办法声明函数的返回类型,假设函数的参数值本身就是MyInterface的参数:
class MyClass<T = MyInterface> {
constructor(private params: T) {
// ...
}
// The question comes here:
get(value: keyof T): T[value] { // Obviously this doesn't work
return this.params[value];
}
}
【问题讨论】:
标签: typescript