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

396
Views
TS7053: El elemento tiene implícitamente un tipo 'cualquiera'

Siento mi pregunta estúpida, pero no puedo buscar la respuesta para mi problema. TS7053: El elemento tiene implícitamente un tipo 'cualquiera' porque la expresión de tipo 'cadena' no se puede usar para indexar el tipo '{ ancho: número; altura: número; título: cadena; }'

 let menu:{width:number; height:number; title:string} = { width: 200, height: 300, title: 'My menu', } function multiplyNumeric(menu:{width:number; height: number; title: string}):void { for (let k in menu){ if (typeof menu[k] === "number"){ menu[k] = Number(menu[k]) * 2; } } } multiplyNumeric(menu);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

TypeScript no sabe qué significa k en el contexto del bucle for dentro de la función multiplyNumeric .

Dado que el tipo de Menu está estrictamente definido y usted está determinando el valor de Menu en tiempo de ejecución, deberá agregar un genérico adicional al tipo de apoyo a Menu , como este:

 type Menu = { width: number; height: number; title: string; [prop: string]: number | string; };
about 4 years ago · Juan Pablo Isaza Report

0

En su función de multiplicación numérica, el parámetro 'menú' tiene un tipo de datos no válido. No se puede configurar así. Por lo que entiendo, quiere que su parámetro de menú sea un objeto con tres propiedades

 { width:number; height: number; title: string }

Necesita definir una interfaz para hacer el trabajo.

 inteface menuObj { width:number; height: number; title: string; }

Y luego haz algo como esto:

 function multiplyNumeric(menu: menuObj)
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!