export class Service {
public validate() {
return async((name: string, dob: string) => {
//do some operation
});
};
public validate() {
return async((name: string, dob: string, address: string) => {
//do some operation
});
};
}
错误:功能重复的实现
Typescript版本:3.8.3
是否可以在打字稿中重载方法?如果“是”,谁能帮助解决上述方法?
我想如果我想您的两个验证函数返回不同的数据类型,例如int和string,那么您可以做这样的事情。
function validate():string;
function validate(): number;
function validate(): any {
return something; //Something can be string or number
}
如果都返回数字该怎么办
public validate() {
return async((name: string, dob: string, address: string) => {
//you can do the operation and check if address is undefined
});
};