Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

80
Views
generic type for fucntion from test-library

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);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!