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

105
Views
desestructuración de retorno mecanografiado?
function print(): (number, string) { return {1,'my'} }

El código anterior muestra un error, espero poder usar const {num, my} = print() . ¿Cuál es la forma correcta de especificar el tipo de retorno?

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

0

Intenta usar una tupla . Se parece a esto:

 function print(): [number, string] { return [1,'my'] } const [num, my] = print();

Ver demostración en Typescript Playground

about 4 years ago · Juan Pablo Isaza Report

0

Debe devolver un objeto que tenga una cadena y un número. Ahora, este objeto debe contener nombres de propiedad; entonces, definamos el tipo de devolución y usémoslo en su función

 type myReturnType = { n: number, s: string } function print():myReturnType { return {n:1,s: 'my'} } let {n, s} = print();

Aquí está la versión abreviada del código anterior:

 function print():{n: number, s: string}{ return {n:1,s: 'my'} } let {n, s} = print();
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!