The reason I ask this question is because I saw the following sentence in official document about module.
The core idea of the pattern is that the import id = require("...")
statement gives us access to the types exposed by the module.
But from the module's own point of view, it is a function that gets executed to add properties to an
exports object passed to it. Generally speaking that
exports object becomes the module to its importers.
The exact form of function for modules generated by TypeScript depends on the loader option you choose. With CommonJS modules for example (used by NodeJS) the function for a module gets automatically wrapped around a .js files's conents by the loader. For Node.js that function normally looks like this:
require() function, etc. Typically the code in the middle works by adding properties to the
That's not quite the whole story, its possible for a module to be something else. If the code in the middle assigns something else to
module.exports, that object becomes the runtime module object. This isn't very common.