When I used Typescript and I got the error below.
I just wanted to loop an object and change values inside them.
But Typescript gave me the error even though it actually worked very well.
How can I remove the error from typescript in this 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);