Skip to content
Advertisement

typescript is there a way to remove the array from an property?

I have this model:

JavaScript

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

JavaScript

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

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

JavaScript

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

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement