"Utilizing Type Parameters within Generic Constraints" on the TypeScript website showcases the following example code. However, an error is thrown:
'Type 'U[keyof U]' is not compatible with type 'T[keyof U]'. Type 'U' cannot be assigned to type 'T'.'
function cloneFields<T extends U, U>(target: T, source: U): T {
for (let id in source) {
target[id] = source[id];
}
return target;
}
let x = { a: 1, b: 2, c: 3, d: 4 };
cloneFields(x, { b: 10, d: 20 });
Interestingly, this code snippet does not execute properly in the Playground. Can you spot what's causing the issue?