反面例子1:
function abc(a: string, b: number): void;
function abc(a: string): void;
function abc(a: any, b:any): void {
if (typeof b === 'number'){}
else {}
}
abc.someAttr = ()=>{};
反面例子2:
interface IAbc {
(a: string, b: number): void;
(a: string): void;
someAttr: ()=>void;
}
let abc: IAbc = (a: any, b:any) => {
if (typeof b === 'number'){}
else {}
}
abc.someAttr = ()=>{};
现在这样凑合着:
interface IAbc {
(a: string, b: number): void;
(a: string): void;
someAttr?: ()=>void; // 加了个问号
}
let abc: IAbc = (a: any, b?:any) => {
if (typeof b === 'number'){}
else {}
}
abc.someAttr = ()=>{};
请问有人知道正确手法吗?