【发布时间】:2019-02-13 00:59:48
【问题描述】:
假设我们有两个变量
const x='property1'
const y='property2'
我们有函数
function foo<key extends keyof MapInterface>(name: key, props: (MapInterface[key]))
这个界面应该是这样的
interface MapInterface{
'property1':any;
'property2':any;
}
是否可以通过调用变量 x,y 来通用地创建接口
interface MapInterface{
x:any; //return 'property1':any;
y:any; //return 'property2':any;
}
【问题讨论】:
标签: typescript interface properties typescript-typings