![](/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.