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

216
Views
¿Cómo usar este tipo genérico en este caso? no se porque

Recientemente aprendí mecanografiado genérico. y lo usé en ciertas situaciones. pero no pude

Cuando usaba dos interfaces diferentes, lo quería.

por ejemplo

Quiero enviar una solicitud de servidor.

 function fetcher async(){ return await axios.get(url).then(data=>data.result) }

y el servidor me da respuestas pero tienen dos tipos diferentes

 // response A interfase AInterface { name: string; age: number; address: string } // response B interfase BInterface { name: string; job : string; haveCar: boolean; }

y establezca el tipo de retorno usando genérico

 function fetcher<T> async():<T>{ return await axios.get(url).then(data=>data.result) } and use function const result = fetcher<AInterface>() or fetcher<BInterface>()

resultado tiene tipo AInterface | BInterfaz

por qué el resultado tiene tipo AInterface | BInterfaz ??

no sé

quiero que tenga AInterface o BInterface. no unión

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No es necesario escribir 'buscador'

Solo usa:

 async function fetcher() { const { data } = await axios.get<AInterface>(url) return data }

O:

 async function fetcher(): Promise<AInterface> { const { data } = await axios.get(url) return data }
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!