![](/img/trans.png)
[英]How can i apply an interface to an anonymous callback function in typescript
[英]in typescript, how do I implement a interface with a callback?
我在带有回调的Typescript中创建了一个接口,该如何实现呢?
interface LoginCallback{
Error: boolean,
UserInfo: {
Id: string,
OrganizationId: string
}
}
interface IntegrationInterface {
Init(): void;
LogIn(UserName: string, Password: string, LoginCallback:LoginCallback): void;
}
您声明LoginCallback
方式意味着它只是一个对象而不是一个函数。 我想这就是你想要的:
interface LoginCallback {
(Error: boolean, UserInfo: { Id: string, OrganizationId: string }): void;
}
interface IntegrationInterface {
Init(): void;
LogIn(UserName: string, Password: string, LoginCallback: LoginCallback): void;
}
然后,您可以执行以下接口:
class IntegrationImpl implements IntegrationInterface {
Init() {
//...
}
LogIn(UserName: string, Password: string, LoginCallback: LoginCallback) {
//...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.