这是我有时使用的一个小实用函数(js),我希望它的输入方式如下:
// original js untypified
function prefixProperties(obj, prefix) {
let out = {};
for (let propt in obj) {
out[prefix + propt] = obj[propt];
}
return out;
}
let x : { num: number, date: Date } = { ... };
let y = prefixProperties(x, 'old');
/*
be great if typeof y was:
{
oldnum: number,
olddate: Date,
};
*/
或者是针对这种功能最具体的方式。
我考虑过元组映射,但我想它们不允许你更改键的名称。
{
[K in keyof T]: whatever
};