It is possible in typescript somehow make possibly empty interface incompatible with string?
interface IA {
foo?:number;
}
function bar(arg:IA) {
}
bar("should not compile");
Added later:
More complex example with possible workaround which is limiting in different way (you can extend only classes or interfaces):
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;
}
In this I found only workaround to extend IAExtended from IACommon but that makes IAExtended also not protected against this bug with passing string instead of object.
classinstead ofinterfaceas a workaround?