<p dir="auto">At first I explain you what I would like to do with tsserver. <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/dbaeumer/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/dbaeumer">@dbaeumer</a> I think you could be interested with this issue for VSCode and Angular2 support.</p>
<p dir="auto">Take the sample <a href="https://angular.io/docs/ts/latest/quickstart.html" rel="nofollow">https://angular.io/docs/ts/latest/quickstart.html</a> with Angular2 &amp; TypeScript. There is a ts file:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import {Component} from 'angular2/angular2';
@Component({
    selector: 'my-app'
})
class AppComponent { }"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span><span class="pl-v">Component</span><span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'angular2/angular2'</span><span class="pl-kos">;</span>
@<span class="pl-v">Component</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
    <span class="pl-c1">selector</span>: <span class="pl-s">'my-app'</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-k">class</span> <span class="pl-v">AppComponent</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span></pre></div>
<p dir="auto">And the HTML:</p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;my-app&gt;&lt;/my-app&gt;"><pre class="notranslate"><span class="pl-kos">&lt;</span><span class="pl-ent">my-app</span><span class="pl-kos">&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">my-app</span><span class="pl-kos">&gt;</span></pre></div>
<p dir="auto">The HTML contains <code class="notranslate">&lt;my-app&gt;</code> which is binded with decorator @Component/selector property. My goal is to provide completion, navigation inside HTML (Eclipse) editor for <code class="notranslate">&lt;my-app&gt;</code>. In other words, I need to collect the whole @Component/selector node of the project to use it in a HTML editor. I tell me how I could do that:</p>
<ul dir="auto">
<li>with TypeScript language service? Develop a walk kind which loop for each <a class="user-mention notranslate" data-hovercard-type="organization" data-hovercard-url="/orgs/component/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/component">@component</a> decorators? If yes, could you give me some info please to do that.</li>
<li>after that I will need to provide this new command to tsserver. So it should be very cool if tsserevr could provide the capability to contribute with custom tsserver command (without compiling a custom tsserver).</li>
</ul>
<p dir="auto">With <a href="http://ternjs.net/doc/demo/#simple" rel="nofollow">ternjs</a> it's possible to write a tern plugin which is able to do that (collect @Component/selector) because:</p>
<ul dir="auto">
<li>ternjs gives the capability to write a tern plugin where you can add your custom function  when AST is walked (to help inference engine to create the well type, or collect modules like I have done with <a href="https://github.com/angelozerr/angularjs-eclipse/wiki/Angular-Explorer-View">Angular Explorer </a>.</li>
<li>ternjs load tern plugin which follow a name pattern (tern-xxxx) from the node_modules to load it. See <a href="https://github.com/ternjs/tern/blob/master/bin/tern#L120">https://github.com/ternjs/tern/blob/master/bin/tern#L120</a></li>
</ul>
<p dir="auto">tsserver could do the same thing by searching inside node_modules with a pattern name like <code class="notranslate">tsserver-xxxx</code> to provide a custom command. After that any editor will be able to consume it just by installing with `npm installl tsserver-angular2'</p>
<p dir="auto">Hope you will understand my issue.</p>
<p dir="auto">Say I'm writing a declaration file for an external library that both exposes a global and supports CommonJS. According to the handbook I would write that like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="module zoo {
  function open(): void;
}

declare module &quot;zoo&quot; {
    export = zoo;
}"><pre class="notranslate"><code class="notranslate">module zoo {
  function open(): void;
}

declare module "zoo" {
    export = zoo;
}
</code></pre></div>
<p dir="auto">And then the usage would be this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="// Either
import x = require('zoo');
x.open();
// or
zoo.open();"><pre class="notranslate"><code class="notranslate">// Either
import x = require('zoo');
x.open();
// or
zoo.open();
</code></pre></div>
<p dir="auto">The problem is that while the above would compile when using external modules, at run-time it would fail since the "zoo" identifier doesn't actually exist. Is there any way to write declaration files such that you can split them into two separate files (one for internal, one for external) so that you only reference the one you intend on using but not actually duplicate the definitions in those files? For example</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="// zoo.d.ts
declare module &quot;zoo&quot; {
    export = zoo;
}

// zoo-internal.d.ts

/// &lt;reference path=&quot;zoo.d.ts&quot; /&gt;
module zoo {
  // this doesn't work but illustrates what I'm trying to accomplish
  import zoo = require('zoo')
  export = zoo;
}"><pre class="notranslate"><code class="notranslate">// zoo.d.ts
declare module "zoo" {
    export = zoo;
}

// zoo-internal.d.ts

/// &lt;reference path="zoo.d.ts" /&gt;
module zoo {
  // this doesn't work but illustrates what I'm trying to accomplish
  import zoo = require('zoo')
  export = zoo;
}
</code></pre></div>
<p dir="auto">Or any thoughts on another way to accomplish the same goals in a single file?</p>