In my React component, I want to define a property to accept any arbitrary function which returns a value. I do not want to worry about the number of arguments it take.. All that matters to me in the return value of that function.
Some sample expected usages:
<MyComponent getData={function1()}/>
<MyComponent getData={function2(1,2)}/>
<MyComponent getData={function3("hello")}/>
Currently I have defined my component property interface as below.
interface MyComponentProps {
getData: (...args: any[]) => any;
}
With the above declarations, I get that getData is not a function error in console.
But the below variations work.
<MyComponent getData={() => function1()}/>
<MyComponent getData={() => function2(1,2)}/>
<MyComponent getData={() => function3("hello")}/>
How should I change my type definition so that I can pass any function as a value to the property?