0

I created an interface in typescript with callback, how do I implement it?

interface LoginCallback{
    Error: boolean,
    UserInfo: {
        Id: string,
        OrganizationId: string
    }
}

interface IntegrationInterface {
    Init(): void;
    LogIn(UserName: string, Password: string, LoginCallback:LoginCallback): void;
}

1 Answer 1

1

The way you declared LoginCallback means it's just an object rather than a function. I assume this is what you wanted:

interface LoginCallback {
    (Error: boolean, UserInfo: { Id: string, OrganizationId: string }): void;
}

interface IntegrationInterface {
    Init(): void;
    LogIn(UserName: string, Password: string, LoginCallback: LoginCallback): void;
}

Then to implement the interface you can do:

class IntegrationImpl implements IntegrationInterface {
    Init() {
       //... 
    }
    LogIn(UserName: string, Password: string, LoginCallback: LoginCallback) {
     //...   
    }

}
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.