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

348
Views
¿Cómo restar dos números en TypeScript?

Estoy tratando de restar dos números pero obtengo The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. :

 const ls = Object.values(localScore)[0]; const s = Object.values(score)[0]; console.log(typeof ls); // number console.log(typeof s); // number const diff = s - ls; // ^ The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

¿Que estoy haciendo mal? Estoy usando TypeScript.

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

0

Si bien las claves de objeto están ordenadas de forma determinista en algunos entornos de tiempo de ejecución, aún no es seguro realizar operaciones en valores contenidos en dos objetos separados, accediendo a ellos mediante un índice numérico correlacionado.

De acuerdo con la información de su comentario , parece que no conoce el nombre de la propiedad que contiene el valor al que desea apuntar en cada objeto, pero sí sabe que el nombre es el mismo en ambos objetos, por lo que es más seguro enfoque sería:

Parque infantil TS

 /** Given that values in the objects are correlated by property key: */ function getDiff < K extends PropertyKey, T extends Record<K, number>, >(minuend: T, subtrahend: T, key: K): number { return minuend[key] - subtrahend[key]; } type NumberValues = Record<string, number>; declare const localScore: NumberValues; declare const score: NumberValues; const [key] = Object.keys(localScore); // destructure first enumerable property key const diff = getDiff(score, localScore, key); // number, but possibly negative const absoluteDiff = Math.abs(diff);
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!