I think you're trying to call the function f
with either a string or a number.
In your interface, you define the overloads like this:
interface X{
b(s:string) : string;
f (s:string):string;
f (s:number):string;
}
And you implement the interface like this.
class xxx implements X
{
b(s:string) : string
{
return "";
}
f (s: string): string;
f (s: number) : string;
f (s: any) : string {
return s.toString();
}
}
Here is complete example you can paste into the Playground to try:
interface X {
b(s:string) : string;
f (s:string):string;
f (s:number):string;
}
class xxx implements X {
b(s:string) : string {
return "";
}
f (s: string): string;
f (s: number) : string;
f (s: any) : string {
return s.toString();
}
}
var x = new xxx();
alert(x.f("1"));
alert(x.f(5));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…