I enjoy customizing my console logs.
//-- Personalized console logging functions
console.detailed = function(payload) {
return console.log(util.inspect(payload, { showHidden: false, depth: null }))
}
console.notice = function(payload) {
return console.log('\x1b[33m%s\x1b[0m', payload)
}
Recently I started using TypeScript and encountered an error that says
Property 'detailed' does not exist on type 'Console'
or
Property 'notice' does not exist on type 'Console'.
If anyone could help me resolve this issue, it would be much appreciated.
Update: In response to Saravana's answer, can someone explain the solution in simpler terms?
In TypeScript, when a file contains a top-level import or export, it is considered a module. Otherwise, a file without these declarations is treated as a script available in the global scope. You may need to wrap your code inside global if you are working within a module context.
Additionally,
If you are facing this issue while working within a module, consider wrapping your code inside the global scope. For more information, refer to this link