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

110
Views
mecanografiado da a la propiedad le falta un tipo

Tengo una función con algunos valores predeterminados, cuando trato de llamar a la función y dado que tiene algunos valores predeterminados, no necesito pasar ningún valor predeterminado, por ejemplo.

 function myFunc( { str1, str2, timeout = 3000, } : { str1: string, str2: string, timeout: number, } ): Promise<any | undefined> { // some logics here } await myFunc({ str1: 'string 1', str2: 'string 2' })

me sale un error como

 Property 'timeout' is missing in type '{ str1: string; str2: string; timeout: number;}'

¿Cómo puedo resolver esto ya que hay un valor predeterminado declarado, no debería tener que pasar la propiedad si no necesito anular el valor predeterminado, no es así?

Gracias de antemano por cualquier ayuda y sugerencia.

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

0

Esta sección es solo sintaxis de JavaScript:

 function myFunc( { str1, str2, timeout = 3000, }

que asignará un valor de 3000 si ese parámetro no está definido. También necesitas indicarle a TypeScript cuál debe ser el tipo del parámetro, y esto:

 { str1: string, str2: string, timeout: number, }

requiere timeout para ser una propiedad.

Si desea que sea opcional, tenga en cuenta que también en el tipo TypeScript, además de usar el valor predeterminado para el JavaScript (emitido).

 function myFunc( { str1, str2, timeout = 3000, } : { str1: string, str2: string, timeout?: number, } ): Promise<any | undefined> { // some logics here }
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!