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;
}
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) {
//...
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.