<p dir="auto">Problem: in the current state of affairs although convenient to certain audiences the bivariance is a gaping hole in the type system</p>
<p dir="auto">Solution:</p>
<ul dir="auto">
<li>allow optional but explicit <code class="notranslate">in</code> and <code class="notranslate">out</code> modifiers like in C# for those who wants to take advantage of stricter typechecking</li>
<li>keep bivariant typechecking for anyone who doesn't care:</li>
</ul>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Array&lt;a&gt; {
   map:  &lt;b&gt;(map: (value: a) =&gt; b) =&gt; b[];
)

declare var animals: Array&lt;Animal&gt;;
declare var copyCat: (cat: Cat) =&gt; Cat

animals.map(copyCat); // expected not to typecheck, currently allowed no problem

// but if we go

Array&lt;in a&gt; {
   map:  &lt;b&gt;(map: (value: a) =&gt; b) =&gt; b[];
)

// then

animals.map(copyCat); // doesn't typecheck anymore as expected
"><pre class="notranslate"><span class="pl-smi">Array</span><span class="pl-c1">&lt;</span><span class="pl-s1">a</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
   <span class="pl-c1">map</span>:  <span class="pl-kos">&lt;</span><span class="pl-smi">b</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">map</span>: <span class="pl-kos">(</span><span class="pl-s1">value</span>: <span class="pl-smi">a</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">b</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">b</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-kos">)</span>

<span class="pl-k">declare</span> <span class="pl-s1">var</span> <span class="pl-s1">animals</span>: <span class="pl-smi">Array</span><span class="pl-kos">&lt;</span><span class="pl-smi">Animal</span><span class="pl-kos">&gt;</span><span class="pl-kos">;</span>
<span class="pl-k">declare</span> <span class="pl-s1">var</span> <span class="pl-en">copyCat</span>: <span class="pl-kos">(</span><span class="pl-s1">cat</span>: <span class="pl-smi">Cat</span><span class="pl-kos">)</span> <span class="pl-c1">=</span><span class="pl-c1">&gt;</span> <span class="pl-smi">Cat</span>

<span class="pl-s1">animals</span><span class="pl-kos">.</span><span class="pl-en">map</span><span class="pl-kos">(</span><span class="pl-s1">copyCat</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// expected not to typecheck, currently allowed no problem</span>

<span class="pl-c">// but if we go</span>

<span class="pl-smi">Array</span><span class="pl-c1">&lt;</span><span class="pl-s1">in</span> <span class="pl-s1">a</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
   <span class="pl-c1">map</span>:  <span class="pl-kos">&lt;</span><span class="pl-smi">b</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">map</span>: <span class="pl-kos">(</span><span class="pl-s1">value</span>: <span class="pl-smi">a</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">b</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">b</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-kos">)</span>

<span class="pl-c">// then</span>

<span class="pl-s1">animals</span><span class="pl-kos">.</span><span class="pl-en">map</span><span class="pl-kos">(</span><span class="pl-s1">copyCat</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// doesn't typecheck anymore as expected</span></pre></div>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="122126951" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/6102" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/6102/hovercard" href="https://github.com/microsoft/TypeScript/issues/6102">#6102</a> spinoff</p>
<p dir="auto">Hi,</p>
<p dir="auto">I have this line wich i took from a javascript code but forgot to add "=" when converting.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="public require: &quot;ngModel&quot;;"><pre class="notranslate"><span class="pl-k">public</span> require: <span class="pl-s">"ngModel"</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">It compiles ok. Im pretty sure it should not because the line is not in the corresponding .js!</p>
<p dir="auto">Tryed to search for duplicate but its a bit hard to find the right search terms.</p>
<p dir="auto">Is it normal?</p>
<p dir="auto">Thanks.</p>
<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.8.9</p>
<p dir="auto"><strong>Expected behavior:</strong><br>
Compilation error. (I wish)</p>
<p dir="auto"><strong>Actual behavior:</strong><br>
Compiles with no errors, but the code is not inside the generated .js</p>