How To Use Typescript Modules
<p>I'm having a bit of difficulty understanding how to correctly create a typescript module.</p>

<p>What I'm trying to achieve is 1 module per file, with no variables leaking into the global scope.</p>

<p>If I have a js file called "shoppingCart.js" for example, with a function within it called "addItem()", I want to only ever be able to access addItem, via "shoppingCart.addItem()".</p>

<p>I can achieve this by creating shoppingCart.js and putting the addItem() function within it, but upon first glance, it appears that the addItem() function is globally scoped.</p>

<p>If I wrap the contents of shoppingCart.js in a module called "shoppingCart", it looks like I get the encapsulation I'm after, however, when I import the module, it's like I have to double name it, e.g.:</p>

<p>import shoppingCart from './shoppingCart'
shoppingCart.shoppingCart.addItem()</p>

<p>I know I could just change the variable on the import statement to something else, but I don't want to, I just want to type in "shoppingCart." and have access to all of it's exported functions classes and variables.</p>

<p>Should I even be using the "module" keyword?
I wanted to use "module" at the root of a module, and only use classes as object containers (And possibly highly related functions where appropriate).</p>

<p>My tsconfig.json has the following properties of interest:</p>

<pre><code>"target": "es5",
"module": "commonjs",
"moduleResolution": "node"
</code></pre>

<p>I'm not sure if it makes a difference, but I'm allowing visual studio 2015 to convert the .ts files to .js files, then using browserify with a gulp build process, to concatenate them all into a single file.</p>