<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="interface OverloadedMethod {
    (a:string): Object;
    (a:number): void;
}

const bar : string|number = 0;
const foo : OverloadedMethod = null;
foo(bar) // red squiggles here under bar: Argument of type 'string | number' is not assignable to 'string'. Type 'string | number' is not assignable to 'number'"><pre class="notranslate"><code class="notranslate">interface OverloadedMethod {
    (a:string): Object;
    (a:number): void;
}

const bar : string|number = 0;
const foo : OverloadedMethod = null;
foo(bar) // red squiggles here under bar: Argument of type 'string | number' is not assignable to 'string'. Type 'string | number' is not assignable to 'number'
</code></pre></div>
<p dir="auto">This is a minimal example of where typescript complains that <code class="notranslate">bar</code> cannot unify with any of the individual methods on <code class="notranslate">foo</code>, even though it could reasonable deduce that since there's only one implementation of said method, that <code class="notranslate">(a:string|number) : Object|void</code> is a perfectly cromulent alternative.</p>
<p dir="auto">Looks like this is a consequence of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="118539367" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/5766" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/5766/hovercard" href="https://github.com/microsoft/TypeScript/issues/5766">#5766</a> and it rears it head when dealing w/ Express routing's d.ts.</p>
<p dir="auto">The type guard <code class="notranslate">instanceof Array</code> does not seem to recognize the type of the interface IMessage.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="interface IMessage {
    name: string;
}

function itemFn(pipIn: IMessage[]) {
    return pipIn;
}

function baseFn(pipIn: IMessage) {
    return [pipIn];
}

function main(pipIn: IMessage|IMessage[]) {
    if (pipIn instanceof Array) {
        return itemFn(pipIn);
    } else {
        return baseFn(pipIn);
    }
}"><pre class="notranslate"><code class="notranslate">interface IMessage {
    name: string;
}

function itemFn(pipIn: IMessage[]) {
    return pipIn;
}

function baseFn(pipIn: IMessage) {
    return [pipIn];
}

function main(pipIn: IMessage|IMessage[]) {
    if (pipIn instanceof Array) {
        return itemFn(pipIn);
    } else {
        return baseFn(pipIn);
    }
}
</code></pre></div>
<p dir="auto">The compiler outputs the error message:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="unions6.ts(19,23): error TS2345: Argument of type 'IMessage | IMessage[]' is not assignable to parameter of type 'IMessage'.
  Type 'IMessage[]' is not assignable to type 'IMessage'."><pre class="notranslate"><code class="notranslate">unions6.ts(19,23): error TS2345: Argument of type 'IMessage | IMessage[]' is not assignable to parameter of type 'IMessage'.
  Type 'IMessage[]' is not assignable to type 'IMessage'.
</code></pre></div>
<p dir="auto">I'm using master of today.</p>
<p dir="auto">Thanks</p>