[英]Typescript strongly type void Function
I'm trying to write an interface which takes a function in as a parameter: 我正在尝试编写一个将函数作为参数的接口:
Currently I'm trying this 目前我正在尝试
export interface EditOptions {
isEditing: boolean;
save: () => {};
}
I've tried a few things to assign the function: 我尝试了一些分配功能的方法:
editOptions: EditOptions = { isEditing: false, save: this.save };
editOptions: EditOptions = { isEditing: false, save: () => { this.save() } };
Neither work instead I receive this error: 两者都不起作用,但我收到此错误:
I Know that for now I can use :any
but what is the proper way to strongly type a void function 我知道现在我可以使用
:any
但是强类型键入void函数的正确方法是什么?
interface you can define as : 您可以将接口定义为:
export interface EditOptions {
isEditing: boolean;
save: () => void;
}
and you can use/assign it as : 您可以将其使用/分配为:
editOptions: EditOptions = { isEditing: false, save: () => { this.anyFunction() } };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.