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

168
Views
Función encadenable de JavaScript/Typescript sin clase

Estoy tratando de codificar correctamente mi función encadenable en Typescript. A continuación se muestra el código

 const sum = (val: number | undefined) => { let internal = Number(val); if (val) { return function sumup(_val: number | undefined) { if (_val && internal !== undefined) { internal += _val; return sumup; } return internal; }; } return internal; }; console.log('sum:', sum(1)(2)(3)());

La función está funcionando hasta el punto de que obtengo el resultado correcto. Sin embargo, está generando un error de mecanografiado: This expression is not callable. Not all constituents of type 'number | ((_val: number | undefined) => number | ...)' are callable. Type 'number' has no call signatures.

¿Cómo codificaría correctamente una función de sum sin usar class o this ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede lograr esto describiendo con precisión los comportamientos de las funciones con sobrecargas de funciones:

 function sum(): number function sum(val: number): typeof sum function sum(val?: number): number | typeof sum { let internal = Number(val); if (val) { function sumup(): number function sumup(_val: number): typeof sumup function sumup(_val?: number): number | typeof sumup { if (_val && internal !== undefined) { internal += _val; return sumup; } return internal; }; return sumup; } return internal; }; console.log('sum:', sum(1)(2)(3)());

patio de recreo mecanografiado

over 4 years ago · Santiago Trujillo 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!