My questions are around working with commonJS (node style) and ES6 modules (using typescript). I have this angular 1.5 app which uses the commonJS module system. I attempted to use typescript for creating just one of the factories in the app. Few questions on the same.
Can we use typescript import keyword to import a module exported using the commonJS module.exports syntax? For example, say we have RandomService.js below that we wish to use in our typescript file. I noticed that doing an import * as randomservice from '../../services/RandomService.js' threw some errors related to not being able to find the module. I got this to work by using a require(), but just wanted to know if this can be done in typescript?
var randomString = require('random-string'); module.exports = { getSuperRandom: function() { var x = 'super-random-' + randomString(); return x; } }
When we export a module from a typescript file usually the exports object has a property which holds our object. Even doing an export default results in the .default property having our exported object. Is there anyway where we can set the exported object directly to the exports object (just like we can do in commonJS module system where we do module.exports = 'helloservice')?