0

I need to implement some count of interfaces (IUserAccess for example).

All of these interfaces inherit the IBase interface which contains an Execute method, so I want to implement IBase just one time.

Like this:

class IBase{
  Execute(data: any): void{
    console.log('Execute');
  };

interface IUserAccess extends IBase {
  CheckPassword(username: string, password: string): boolean;
}

class UserAccess implements IUserAccess{
  CheckPassword(username: string, password: string): boolean {
    console.log('CheckPassword');
    Execute({...});
    ...
  }

}

But IDE says:

>Class 'UserAccess' incorrectly implements interface 'IUserAccess'.  
Property 'Execute' is missing in type 'UserAccess' but required in type 'IUserAccess'.

How I can resolve my issue?

3
  • It seems when you extend class with interface, you loose method implementations, so you will have to implement Execute in UserAccess class. Commented Apr 9, 2019 at 8:12
  • But implement of Execute in UserAccess class is bad solution for me because I need to implement more than 20 interfaces each of them have the same Execute method and I dont want to make a copypast of Execute body for each interface implementation Commented Apr 9, 2019 at 8:23
  • I guess you can skip interface and just extend IBase like class UserAccess extends IBase and access Execute like this.Execute({...}) Commented Apr 9, 2019 at 8:28

1 Answer 1

2

Possible solution

class IBase{
  Execute(data: any): void{
    console.log('Execute');
  };
}

interface IUserAccess {
  CheckPassword(username: string, password: string): boolean;
}

class UserAccess extends IBase implements IUserAccess {
  CheckPassword(username: string, password: string) {
    console.log('CheckPassword');
    this.Execute({...});
    ...
    return true;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.