<p dir="auto"><strong>TypeScript Version:</strong></p>
<p dir="auto">1.8.10</p>
<p dir="auto"><strong>Code</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="declare function overload(param: number);
declare function overload(param: string);

let bar: number | string;
overload(bar); // Argument of type 'number' | 'string' is not assignable to parameter of type 'string'"><pre class="notranslate"><span class="pl-k">declare</span> <span class="pl-k">function</span> <span class="pl-s1">overload</span><span class="pl-kos">(</span><span class="pl-s1">param</span>: <span class="pl-smi">number</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">declare</span> <span class="pl-k">function</span> <span class="pl-s1">overload</span><span class="pl-kos">(</span><span class="pl-s1">param</span>: <span class="pl-smi">string</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">let</span> <span class="pl-s1">bar</span>: <span class="pl-smi">number</span> <span class="pl-c1">|</span> <span class="pl-smi">string</span><span class="pl-kos">;</span>
<span class="pl-en">overload</span><span class="pl-kos">(</span><span class="pl-s1">bar</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// Argument of type 'number' | 'string' is not assignable to parameter of type 'string'</span></pre></div>
<p dir="auto"><strong>Expected behavior:</strong><br>
Since the function 'overload' either accepts a 'number' or a 'string', the compiler should not complain.</p>
<p dir="auto"><strong>Actual behavior:</strong><br>
The compiler complains with: "Argument of type 'number' | 'string' is not assignable to parameter of type 'string'".</p>
<p dir="auto"><strong>Workaround:</strong><br>
Of course I could always rewrite the declaration of 'overload' as:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="declare function overload(param: number | string);"><pre class="notranslate"><span class="pl-k">declare</span> <span class="pl-k">function</span> <span class="pl-s1">overload</span><span class="pl-kos">(</span><span class="pl-s1">param</span>: <span class="pl-smi">number</span> <span class="pl-c1">|</span> <span class="pl-smi">string</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">But usually these declarations are from external *.d.ts files which I do not want to touch if I don't have to.</p>
<p dir="auto">I was just working with Big.js and tried to pass a union type into its constructor function.  It seems that union types don't play nice with old-style overloaded constructors.  Please consider the code below that errors with TypeScript 1.4.  I would have expected this to work.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
interface BigJS_Constructors {
    new (value: number): BigJS;
    new (value: string): BigJS;
    new (value: BigJS): BigJS;
}

interface BigJS extends BigJS_Constructors {
    abs(): BigJS;
    /* more... */
}

var Big : BigJS;

class MyThing {
    public value : BigJS;
    constructor(value: number | string | BigJS) {
        this.value = new Big(value); //This is an error in 1.4.
    }
}"><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-smi">BigJS_Constructors</span> <span class="pl-kos">{</span>
    <span class="pl-k">new</span> <span class="pl-kos">(</span><span class="pl-s1">value</span>: <span class="pl-smi">number</span><span class="pl-kos">)</span>: <span class="pl-smi">BigJS</span><span class="pl-kos">;</span>
    <span class="pl-k">new</span> <span class="pl-kos">(</span><span class="pl-s1">value</span>: <span class="pl-smi">string</span><span class="pl-kos">)</span>: <span class="pl-smi">BigJS</span><span class="pl-kos">;</span>
    <span class="pl-k">new</span> <span class="pl-kos">(</span><span class="pl-s1">value</span>: <span class="pl-smi">BigJS</span><span class="pl-kos">)</span>: <span class="pl-smi">BigJS</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">interface</span> <span class="pl-smi">BigJS</span> <span class="pl-k">extends</span> <span class="pl-smi">BigJS_Constructors</span> <span class="pl-kos">{</span>
    <span class="pl-c1">abs</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">BigJS</span><span class="pl-kos">;</span>
    <span class="pl-c">/* more... */</span>
<span class="pl-kos">}</span>

<span class="pl-k">var</span> <span class="pl-smi">Big</span> : <span class="pl-smi">BigJS</span><span class="pl-kos">;</span>

<span class="pl-k">class</span> <span class="pl-smi">MyThing</span> <span class="pl-kos">{</span>
    <span class="pl-k">public</span> <span class="pl-c1">value</span> : <span class="pl-smi">BigJS</span><span class="pl-kos">;</span>
    <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-s1">value</span>: <span class="pl-smi">number</span> <span class="pl-c1">|</span> <span class="pl-smi">string</span> <span class="pl-c1">|</span> <span class="pl-smi">BigJS</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">value</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Big</span><span class="pl-kos">(</span><span class="pl-s1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">//This is an error in 1.4.</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">If I change the <code class="notranslate">new</code> signature under <code class="notranslate">BigJS_Constructors</code> to <code class="notranslate">new (value: number | string | BigJS) : BigJS;</code>, and eliminate the other two options, it works fine, but to me the two styles should be identical in this case.</p>
<p dir="auto">My apologies if I'm doing something stupid here.  Thanks!</p>