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

133
Visualizações
typescript extend new property without modifying existing type

I have this code

type VehicleDetails = {made: string}

function doSomethingWithVehicleDetails (details: VehicleDetails) { //what to add here for newProperty?
  console.log(details);
}

doSomethingWithVehicleDetails({ made: '123', newProperty: true })

https://www.typescriptlang.org/play?noUncheckedIndexedAccess=true&target=99&useUnknownInCatchVariables=true&exactOptionalPropertyTypes=true#code/FDAuE8AcFMAIDVoAsCWBjANtAItUBDFDAZ1gF5YBvAW3wBNoAuWY0AJxQDsBzAXxABmAV05pQKAPadYdCQGUJ1PKh4B1FKCSJUmHHkIlYACgYEixZtvRZcZkgEoqsAPTOA7knyhYoCbHp0sEjQbHACEmywnNBuAApsEjBsEAD8wLCwaFLEElgAdBgS3Cb65vYA3MD8wLIKSppc3OqaVrq2BsRGlLC0DMwA5ACMAEwAzP0ANFEx8YkhEMzsQnC89kA

without modifying type VehicleDetails = {made: string}, how can I add newProperty in doSomethingWithVehicleDetails argument to fix the error?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could do something like this:

type VehicleDetails = {made: string};

function doSomethingWithVehicleDetails (details: VehicleDetails & { newProperty: boolean }) { 
  console.log(details);
}

doSomethingWithVehicleDetails({ made: '123', newProperty: true });
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