I have this model:
JavaScript
x
5
1
export interface SizeAndColors {
2
size: string;
3
color: string;
4
}[];
5
and then I have another model and I need the sizeAndColor but without a array.
JavaScript
1
4
1
export interface Cart {
2
options: SizeAndColors
3
}
4
How can I say at options that I want to have this interface without the array? is that possible ?
Advertisement
Answer
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:
JavaScript
1
6
1
interface SizeAndColorsElement {
2
size: string;
3
colors: string;
4
}
5
export type SizeAndColors = SizeAndColorsElement[];
6
But if you can’t, you can use SizeAndColors[number]
to access just the object part of that:
JavaScript
1
4
1
export interface Cart {
2
options: SizeAndColors[number];
3
}
4
Again: That’s assuming it’s really defined as an array type, which it doesn’t seem to be in the question’s code.