Reputation: 7792
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;
}
Upvotes: 0
Views: 159
Reputation: 1326
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) {
//...
}
}
Upvotes: 1