0

I created a type in TypeScript:

type SomeType = Array<{...}>;

It defines an array of objects with many different properties in place of the ....

I'd like to create another type that should have the exact same structure as SomeType, just without the array ..so basically I need only that object definition from it like:

type SomeOtherType = {...};

Is there some way to create SomeOtherType based on SomeType so I don't have to list all properties of that object again creating redundancy in the code?

I don't want to use interfaces this time, I'd like to know how this would be possible with types.

I read this but couldn't figure it out based on the docs. Maybe mapped types is what I need?

tom
  • 2,137
  • 2
  • 27
  • 51

1 Answers1

0

Given

type SomeType = Array<{...}>;

you can get the type {...} by looking at the first position using lookup types:

type SomeOtherType = SomeType[0];
basarat
  • 261,912
  • 58
  • 460
  • 511