While utilizing Typescript, I encountered the issue described below.
My intention was to iterate through an object and modify its values.
Despite the functionality working smoothly, Typescript flagged it with an error.
How can I resolve this Typescript error in the given script?
const info = {
id: "slkmd",
password: "asdfasdf!",
num: 1
}
const target = {
id: "asdf",
password: "asdf",
num: 21
}
Object.keys(info).forEach(key => {
info[key as keyof typeof info] = target[key as keyof typeof target]; // Error
// Type 'string | number' is not assignable to type 'never'.
// Type 'string' is not assignable to type 'never'
});
console.log(info);