I want to make an extension method so I can easily print out any typescript primitive or object in human-readable form. So instead of doing JSON.stringify(thing)
I can do thing.printNice()
Is this possible? I tried this but it doesn't work:
interface any {
printNice(): string
}
any.prototype.printNice = function() {
return JSON.stringify(this)
}
Edit: I see now that this has been asked and the answer is no, you can't.
Is there any way to accomplish what I am trying to do? Typing JSON.stringify(thing)
all over the place is annoying.