这是棘手的功能:
function getPropertyName(obj, expression) {
var res = {};
Object.keys(obj).map(k => { res[k] = () => k; });
return expression(res)();
}
我尝试键入它失败:
getPropertyName<T>(obj: T, expression: (o: T) => any): string {
let res = {};
Object.keys(obj).map(k => { res[k] = () => k; });
return expression(res as T)();
}
答案 0 :(得分:0)
这不会给您任何错误,但是,您的意图对我而言并不完全清楚:
getPropertyName<T>(obj: T, expression: (o: T) => any): string {
const res: { [key: string]: any } = {};
Object.keys(obj).map((k) => { res[k] = () => k; });
return expression(res as T)();
}