Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

enter image description here

I Know that for now I can use :any but what is the proper way to strongly type a void function

like image 667
johnny 5 Avatar asked Oct 25 '25 16:10

johnny 5


1 Answers

Hidden away from the docs it exists VoidFunction:

interface Example {
 save: VoidFunction;
}

const example: Example = {save: () => { this.saveForReal(); } };
like image 143
Lucio Avatar answered Oct 28 '25 07:10

Lucio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!