0
如何重载函数我想在typescript中扩展原生的javascript类型。这可以使用一个接口来声明扩展属性。 但如何声明重载的属性?Typescript:接口
interface HTMLElement {
add:(a:string)=>void; // error: add is duplicate
add:(a:boolean)=>void;
}
HTMLElement.prototype.add = function (a):void{
if(typeof a=="string"){
}
else if(typeof a=="boolean"){
}
}
class HTMLElement2 {
add(a:string):void; // ok
add(a:boolean):void;
add(a):void{
if(typeof a=="string"){
}
else if(typeof a=="boolean"){
}
}
}
谢谢
我不知道为什么我没有尝试过。很明显。 – Baud