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
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
- 1 Does the troll care to explain the down vote – johnny 5 Commented Jul 27, 2017 at 3:19
2 Answers
Reset to default 6Hidden away from the docs it exists VoidFunction
:
interface Example {
save: VoidFunction;
}
const example: Example = {save: () => { this.saveForReal(); } };
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() } };