In the video I’ve found that interfaces can use strange overload technique. The code below is compiled but does not work.
I have some questions, all of them are placed inside of the code:
interface X{
// how can the class implements such overload ?
f:{
(s:string):string;
(s:number):string;
data:any;
};
}
class xxx
{
// how to initialize this structure ?
f:{
(s:string):string;
(s:number):string;
data:any;
};
}
var x = new xxx();
// how should the class xxxx look to be used with this function ?
function a(x:X):string{
return x.f("1");
}
a(x);
The only solution I’ve found is to use type cast. It works, but looks quite ugly. To me this is an error in the compiler or there should be different way to do this.
UPD: Indeed, this is the only solution, http://typescript.codeplex.com/discussions/401235