I have a main.ts and a helper.ts. In the helper.js I tried to override console.log and export it so I could use the code in my main.js, but when I run a console.log() it crashes with the error below. I was trying to adapt this SO Answer. What am I missing here?
I am transpiling Typescript files to JS using ts-node main.ts
Error in main.ts:
ReferenceError: window is not defined
I tried to fix this by adding at the bottom of helper.ts: (this as any).window.console = console;
but got the same error.
helper.ts
export var console = (function(oldCons) {
return {
log: function(text: any) {
oldCons.log("WHEEE" + text);
// Your code
},
info: function(text: any) {
oldCons.info(text);
// Your code
},
warn: function(text: any) {
oldCons.warn(text);
// Your code
},
error: function(text: any) {
oldCons.error(text);
// Your code
}
};
})(window.console);
main.ts
import {console} from './helper.ts'
console.log("hi stack overflow")