I have part of code like following, but fail on type checking for error Don't use 'Function' as a type. The 'Function' type accepts any function-like value.. what is the best way for me to provide the type for the function from testing-library/react?
async function onAction(
queryByTestId: Function,
findByTestId: Function,
): Promise<void> {
await waitFor(() => expect(queryByTestId(selector)).toBeVisible());
const triggerChange = await findByTestId('NAME');
}
const {findByTestId, queryByTestId} = render(<Component />);
await onAction(queryByTestId, findByTestId);
The Function type is a very broad type, similar to how large the Object type is. It is recommended to define what the function definition will look like.
From the amount of code you have provided something like this might surfice:
async function onAction(
queryByTestId: (selector: string) => Element | null,
findByTestId: (selector: string) => Promise<Element | null>,
): Promise<void> {
// etc
Alternatively, if you have access to the functions or typings file, you can define the structure there, export the definition and use it in this file.
More reading about function types can be found at Typescript Documentation - More on Functions