Looks like TypeScript has a nice module system, however does this replace the need for something like requirejs? In other words, when you "compile" a typescript package does it handle all the dependency resolution for you? Examples would be appreciated!
TypeScript does not have a runtime module loader. You will still need to provide a module loader to use at runtime, e.g. require js. TypeScript supports generating JavaScript code compatable with either commonJS (for node.js scripts) and AMD loaders (e.g. requireJS). To specify which one to use pass in the "--module " switch to the compiler with either "amd" or "commonjs".
Here is how you export a module in TypeScript:
export module depModule {
export class A {
}
}
and here is the generated JavaScript code with --module amd switch:
define(["require", "exports"], function(require, exports) {
(function (depModule) {
var A = (function () {
function A() { }
return A;
})();
depModule.A = A;
})(exports.depModule || (exports.depModule = {}));
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With