📜  如何在打字稿代码示例中使用变量作为对象键

📅  最后修改于: 2022-03-11 14:48:28.496000             🧑  作者: Mango

代码示例3
// For every properties K of type T, transform it to U
function mapObject(obj: Record, f: (x: T) => U): Record

const names = { foo: "hello", bar: "world", baz: "bye" };
const lengths = mapObject(names, s => s.length);  // { foo: number, bar: number, baz: number }