I'm just learning TypeScript and getting stuck trying to add some methods to the DOM or other existing objects. As an example, I'm trying to add a method I can call to use color in console logging. However, I'm getting a couple of TypeScript errors.
Object.defineProperties(console, {
redLog: function(msg: string) { console.log(`%c${msg}`, 'color:red'); //TS error: Type '(msg: string) => void' has no properties in common with type 'PropertyDescriptor'.
},
});
console.redLog("This should print red") //TS error: Property 'redLog' does not exist on type 'Console'.
Any idea what I'm doing wrong? I'm not sure how to leverage interfaces or whatever TS approach would be needed to allow me to add this console.redLog() method. Thanks for any help!