<p dir="auto">If you have the following code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="interface Api {
     a: string;
     o?: string;
}
var v = { a:'s', i: 5 };
var u : Api = { a:'s', i: 5 };"><pre class="notranslate"><code class="notranslate">interface Api {
     a: string;
     o?: string;
}
var v = { a:'s', i: 5 };
var u : Api = { a:'s', i: 5 };
</code></pre></div>
<p dir="auto">v will be automatically types based on its structure, while u will be typed according to the specified interface Api. As a result the compiler will give the following responses to the following expressions:</p>
<p dir="auto">v.a // string typed<br>
v.i // number typed<br>
v.o // compiler error not in the automatic type<br>
u.a // string typed<br>
u.i // compiler error not in the interface<br>
u.o // string typed</p>
<p dir="auto">I would like support for something that gives me the benefit of both, an automatic type, that i can give it a list of implements, perhaps using a syntax like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var s : &lt;G implements Api&gt; = { a:'s', i: 5 };"><pre class="notranslate"><code class="notranslate">var s : &lt;G implements Api&gt; = { a:'s', i: 5 };
</code></pre></div>
<p dir="auto">that will give me the following responses from the compiler:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="s.a // string typed
s.i // number typed
s.o // string typed"><pre class="notranslate"><code class="notranslate">s.a // string typed
s.i // number typed
s.o // string typed
</code></pre></div>
<p dir="auto">The advantage is that i want to specify the interface so that the compiler can indeed check that i follow whatever is defined in the interface, but still allow me to use things that are not mentioned in the interface.<br>
This is especially useful when i am using an interface with indexer like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="interface IMap&lt;T&gt; {
    [name:string]:T;
}
interface IPolicy {
  dealWithXXX: () =&gt; void;
  // more complex policy options
}
var policies : &lt;G implements IMap&lt;IPolicy&gt;&gt; = {
  policy1 : { dealWithXXX: () =&gt; {
    // To one thing
  } },
  policy1 : { dealWithXXX: () =&gt; {
    // To other thing
  } }
}"><pre class="notranslate"><code class="notranslate">interface IMap&lt;T&gt; {
    [name:string]:T;
}
interface IPolicy {
  dealWithXXX: () =&gt; void;
  // more complex policy options
}
var policies : &lt;G implements IMap&lt;IPolicy&gt;&gt; = {
  policy1 : { dealWithXXX: () =&gt; {
    // To one thing
  } },
  policy1 : { dealWithXXX: () =&gt; {
    // To other thing
  } }
}
</code></pre></div>
<p dir="auto">Here i want the interface to guard me so if i add some additional requirement to IPolicy it will be checked for all the different policies by the compiler, I also want to use the indexer as an getter for selecting the correct policy by name, last i also want to select specific policies as attributes for example for selecting a default policy</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var currentPolicy = policies[policyName] || policies.policy1;"><pre class="notranslate"><code class="notranslate">var currentPolicy = policies[policyName] || policies.policy1;
</code></pre></div>
<p dir="auto">Currently the only cumbersome way to get that is using the following code (that IMHO is not maintainable):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="interface ICurrentPolicies: extends IMap&lt;IPolicy&gt; {
  policy1: IPolicy;
  policy2: IPolicy;
  // continue list here all diffeerent policy names
}

var policies2 : ICurrentPolicies = {
  policy1 : { dealWithXXX: () =&gt; {
    // To one thing
  } },
  policy1 : { dealWithXXX: () =&gt; {
    // To other thing
  } }
}"><pre class="notranslate"><code class="notranslate">interface ICurrentPolicies: extends IMap&lt;IPolicy&gt; {
  policy1: IPolicy;
  policy2: IPolicy;
  // continue list here all diffeerent policy names
}

var policies2 : ICurrentPolicies = {
  policy1 : { dealWithXXX: () =&gt; {
    // To one thing
  } },
  policy1 : { dealWithXXX: () =&gt; {
    // To other thing
  } }
}
</code></pre></div>
<p dir="auto">Here is a common scenario for my open source projects:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="module-a (depends on module-b)
├── bower_components
│   ├── dt-foo (depends on ../dt-node)
│   └── dt-node
│       └── node.d.ts (v0.10)
└── node_modules
    └── module-b
        └── bower_components
            └── dt-node
                └── node.d.ts (also v0.10) &lt;-- conflict!"><pre class="notranslate"><code class="notranslate">module-a (depends on module-b)
├── bower_components
│   ├── dt-foo (depends on ../dt-node)
│   └── dt-node
│       └── node.d.ts (v0.10)
└── node_modules
    └── module-b
        └── bower_components
            └── dt-node
                └── node.d.ts (also v0.10) &lt;-- conflict!
</code></pre></div>
<p dir="auto">A slew of errors result, "Subsequent variable declarations must have the same type," etc. This is, of course, because we are referencing node twice at two different paths, which TypeScript sees as totally different modules, even though they are exactly the same modules, even the same version. As such, it thinks we're trying to redefine things that are already defined. I get it.</p>
<p dir="auto">What I don't get is how to solve the problem gracefully. I've gotten around it, but I'm not happy with my own solution, namely:</p>
<ul dir="auto">
<li>Let <strong>module-a</strong> reference <strong>module-b's</strong> own <code class="notranslate">node.d.ts</code> file so you're always referencing the same file path for Node. Problem solved, but I'm pretty sure it's a Law of Demeter violation. Also, it requires editing bower dependency files to reference the same <code class="notranslate">node.d.ts</code> file, which gets really ugly and hard to maintain.</li>
</ul>
<p dir="auto">Any ideas?</p>