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

248
Views
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 answers
Answer question

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 Report

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 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!