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

258
Visualizações
I'm having a problem passing an argument to a function in typescript

I'm new to Typescript and I'm having trouble passing arguments to a function in Typescript. This function is called when I render a form modal.But I end up getting two errors:

"Argument of type 'Promise<AxiosResponse>' is not assignable to parameter of type '(data: Record<string, unknown>) => Promise'."

"Type 'Promise<AxiosResponse>' provides no match for the signature '(data: Record<string, unknown>): Promise'."

  function openModal(activity) {
    const data = ref({
      name: activity.name,
    })     

    formRender.render(activity, updateActivity(activity.id,{name:data.value.name}))
  }

This would be the function:

export function updateActivity(id: number, data: Record<string, unknown>) {
 return http.patch(`/${id}`, { name: data.name })
}

FormRender:

 export function FormRender<T extends Record<string, unknown>>(formName: string) {
  return {
   render(formAttributes: T | Record<string, unknown>, service: (data: T) => Promise<unknown>) {
     dialog({
      component: FormRender,
      componentProps: {
        formName,
        formAttributes,
        service
     },
  })
},
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

export function updateActivity(id: number, data: Record<string, unknown>) {
 return http.patch(`/${id}`, { name: data.name })
}

This function returns Promise<AxiosResponse<any, any>>. It's an async function which means you'll have to await the result to get the value returned from the HTTP request.

To get the data out of this type you must first await it, and then fetch the data property of the axios response:

export async function updateActivity(id: number, data: Record<string, unknown>) {
  const response = await http.patch(`/${id}`, { name: data.name })
  return response.data // This may require a JSON.parse or further prep depending on what the API returns
}

Now since the service argument is typed as a function, you should be able to pass a function that calls this method:

formRender.render(activity, (data) => updateActivity(activity.id, {name:data.value.name}))

Here's a working example with no type errors

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