-1
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
    });
};

}

Error: Duplicate function implementation

Typescript Ver: 3.8.3

Is it possible to overload the method in the typescript? if "yes" can anyone help to resolve the above methods?

1 Answers1

1

I think if I suppose your two validate function return different data type such as int and string then you may do something like this.

function validate():string;

function validate(): number;

function validate(): any {
    return something; //Something can be string or number 
}

What if both return number

    public validate() {
    return async((name: string, dob: string, address: string) => {
        //you can do the operation and check if address is undefined
    });
};
sourav satyam
  • 980
  • 5
  • 11