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

326
Visualizações
Typescript: How do I define an interface for an object type's key value pair

I have an object called externalObject that has various key:value pairs.

I also have a typescript interface that is defined as the following:

interface TestObject{
   externalObject?: {}
}

My question is how do I further set the type for the externalObject's key as string and the values that are passed inside externalObject as string or number?

Note: we do not always know the key:value pairs. They vary each time.

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

0

You can set any number of key/types on an interface in a similar way to assigning an object. If you don't know the property names ahead of time, you can use a dynamic key:

export interface ITestObject {
  externalObject: {
    [key: string]: string | number;
  };
}

Alternatively, you can set the property as unknown and cast it to the proper type.

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