This is an interesting function:
function extractKey(obj, key) {
var result = {};
Object.keys(obj).forEach(k => { result[k] = () => k; });
return key(result)();
}
Here is a variation of the code:
getKey<T>(obj: T, keyGetter: (o: T) => any): string {
let result = {};
Object.keys(obj).forEach(k => { result[k] = () => k; });
return keyGetter(result as T)();
}