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

256
Visualizações
typescript is there a way to remove the array from an property?

I have this model:

export interface SizeAndColors {
   size: string;
   color: string;
}[];

and then I have another model and I need the sizeAndColor but without a array.

export interface Cart {
  options: SizeAndColors
}

How can I say at options that I want to have this interface without the array? is that possible ?

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

0

Assuming that SizeAndColors really is declared as an array type where the elements are objects with size and color properties (what's in the question [doesn't seem to be that][1]), I'd suggest splitting the original interface:

interface SizeAndColorsElement {
    size: string;
    colors: string;
}
export type SizeAndColors = SizeAndColorsElement[];

But if you can't, you can use SizeAndColors[number] to access just the object part of that:

export interface Cart {
    options: SizeAndColors[number];
}

Again: That's assuming it's really defined as an array type, which it doesn't seem to be in the question's code.

about 4 years ago · Juan Pablo Isaza Relatório

0

Define you interface like this

export interface SizeAndColors {
 size: string;
 color: string;
}

and use array only when you need it

export interface Cart {
 options: SizeAndColors[]
}
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