Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

395
Visualizações
TS7053: Element implicitly has an 'any' type

Sry for my stupid question, but i can`t search answer for my promlem. TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ width: number; height: number; title: string; }'

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 Respostas
Responde à pergunta

0

TypeScript doesn't know what k means in the context of the for loop inside the multiplyNumeric function.

Since the type of Menu is strictly defined, and you are determining the value of Menu at run-time, you will need to add an additional generic to prop type to Menu, like this:

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

0

On your multiplyNumeric function the parameter 'menu' has invalid data type. You cannot set like that. From what i understand you want your menu parameter to be an object with three properties

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

You need to define an interface to do the job.

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

And then do something like this:

function multiplyNumeric(menu: menuObj)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda