I've been working through a book and encountered an issue with the code below.
// This code defines a function called printProperty that has two generic type parameters
function printProperty<T, K extends keyof T>
(object: T, key: K) {
let propertyValue = object[key];
console.log(`object[${key}] = ${propertyValue}`);
}
let obj1 = {
id: 1,
name: "myName",
print() { console.log(`${this.id}`) }
}
printProperty(obj1, "id");
printProperty(obj1, "name");
The error message is:
index.ts(5,25): error TS2731: Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'.
I even tried disabling the strict option in the config file, but it didn't solve the problem.
Any suggestions or assistance would be greatly appreciated!