Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda