How to make possibly empty interface incompatible with string in TypeScript
<p>It is possible in typescript somehow make possibly empty interface incompatible with string?</p>

<pre><code>interface IA {
    foo?:number;
}

function bar(arg:IA) {
}

bar("should not compile");
</code></pre>

<p><a href="http://www.typescriptlang.org/Playground#src=interface%20IA%20%7B%0A%20%20%20%20foo%3F%3Anumber%3B%0A%7D%0A%20%20%0Afunction%20bar(arg%3AIA)%20%7B%0A%7D%0A%20%20%20%20%0Abar(%22should%20not%20compile%22)%3B" rel="nofollow">Playground link</a></p>

<p>Added later:</p>

<p>More complex example with possible workaround which is limiting in different way (you can extend only classes or interfaces):</p>

<pre><code>interface IACommon {
    common?:number;
    f1?:string;
    f2?:any;
}

interface IAWithF1 extends IACommon {
    f1:string;
}

interface IAWithF2 extends IACommon {
    f2:any;
}

type IA = IAWithF1 | IAWithF2;

function bar(arg:IA) {
}

bar("does not compile but next definition also does not compile");

interface IAExtended extends IA {
    ext?: any;
}
</code></pre>

<p><a href="http://www.typescriptlang.org/Playground#src=interface%20IACommon%20%7B%0A%20%20%20%20common%3F%3Anumber%3B%0A%09f1%3F%3Astring%3B%0A%09f2%3F%3Aany%3B%0A%7D%0A%20%0Ainterface%20IAWithF1%20extends%20IACommon%20%7B%0A%09f1%3Astring%3B%0A%7D%0A%0Ainterface%20IAWithF2%20extends%20IACommon%20%7B%0A%09f2%3Aany%3B%0A%7D%0A%0Atype%20IA%20%3D%20IAWithF1%20%7C%20IAWithF2%3B%0A%20%0Afunction%20bar(arg%3AIA)%20%7B%0A%7D%0A%20%20%20%20%0Abar(%22does%20not%20compile%20but%20next%20definition%20also%20does%20not%20compile%22)%3B%0A%0Ainterface%20IAExtended%20extends%20IA%20%7B%0A%09ext%3F%3A%20any%3B%0A%7D%0A" rel="nofollow">Playground link</a></p>

<p>In this I found only workaround to extend <code>IAExtended</code> from <code>IACommon</code> but that makes <code>IAExtended</code> also not protected against this bug with passing string instead of object.</p>