<p dir="auto">Had a ts-typings slack conversation with <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/mhegazy/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/mhegazy">@mhegazy</a> just now, regarding angular2 changing our typings to stop polluting the type-checker with our dependencies.<br>
(details on that change: <a href="https://docs.google.com/document/d/1vgepQPkuHS4P3rzANQpoMIDIXe0Rl9Z2QyTtb8dpMoI/edit#" rel="nofollow">https://docs.google.com/document/d/1vgepQPkuHS4P3rzANQpoMIDIXe0Rl9Z2QyTtb8dpMoI/edit#</a> )</p>
<p dir="auto">While correct, this makes the getting started experience worse for Angular 2 users (many of whom are new to TypeScript and even JavaScript).</p>
<p dir="auto">The major stumbling block is our dependency on es6-promise and es6-collections. For users with <code class="notranslate">--target=es5</code> (the majority and default case), they need these two .d.ts files presented to the compiler. When <code class="notranslate">--target=es6</code>, we must avoid Duplicate identifier errors. We would prefer not to have the <code class="notranslate">typings</code> tool involved in our first five minutes, since we may lose some audience from the complexity and possibility of a mistake ruining their first app.</p>
<p dir="auto">To make it really seamless we need two things:</p>
<ul dir="auto">
<li>If the user has a dependency on angular2, we want the compiler to add es6-promise and es6-collections typings. Imagine if <code class="notranslate">angular2/package.json</code> could declare <code class="notranslate">"ambientTypingsDependencies": ["es6-promise","es6-collections"]</code>. (We don't care what the right-hand side means - it could mean any typing discoverable by <code class="notranslate">typings search</code> but that has versioning issues. It should probably instead be done by splitting <code class="notranslate">lib.es6.d.ts</code> in the TypeScript distro into smaller files, then the option <code class="notranslate">"typingDeps":["XXX"]</code> causes reference to <code class="notranslate">lib.XXX.d.ts</code> and this does not become a general-purpose mechanism. This is really similar to <code class="notranslate">--target=es5+es6-promise+es6-collections</code> except that the user doesn't need to specify it, rather it appears via the dependency on <code class="notranslate">angular2</code>)</li>
<li>No Duplicate identifier errors based on the <code class="notranslate">--target</code> setting. This could be either a fix for <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="78054310" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/3215" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/3215/hovercard" href="https://github.com/microsoft/TypeScript/issues/3215">#3215</a>, or else avoiding the addition of those typings for <code class="notranslate">--target=es6</code>, maybe with something like <code class="notranslate">"typingsDependencies__ButEs5Only": ["es6-promise","es6-collections"]</code></li>
</ul>
<p dir="auto">Referring modules in CommonJS and AMD is quite different. AMD can understand CommonJS (relative paths) to some extent. CommonJS cannot understand AMD mostly.</p>
<p dir="auto">So this is the problem. What do I need to do to share the same code base between CommonJS and AMD? What is a best practice for this?</p>
<p dir="auto">Currently the options known to me are:</p>
<ul dir="auto">
<li>copying the code after compiling so the modules are where the module system can find them</li>
<li>running a path transformation routine over compiled code</li>
</ul>
<p dir="auto">Neither of those look right to me.</p>