I have a file that I want to be able to use both on the server using node.js as well as on the browser.
I conditionally imported an external library using this line. On the browser, I assume that XRegExp is already defined.
if (typeof require !== 'undefined') XRegExp = require('xregexp').XRegExp;
and I conditionally exported the code using this line
if (typeof module !== 'undefined' && !module.exports) module.exports = ret;
How can I do the same thing in TypeScript without the compiler complaining?
You can try the following: