I have a function with optional parameters that I am passing down to another component.
execute = (option: string = 'default'): void => {
// ...
}
In the receiving component, there is a property called executeFunction
where I intend to assign this function. What should be the correct type for this property?
My Attempt
If I define the property as follows, I am unable to provide any arguments when calling it.
executeFunction: () => void;
If I define the property like this instead, I cannot invoke it without providing a parameter value.
executeFunction: (param: string) => void;
When defining the field like this, I compromise on type safety.
executeFunction: any;