0

Let's say I have a type defined as:

type ExistingType = {
  [key: string]: any;
  name: string;
  mobile?: string;
}

Now I want to create a type from this without the arbitrary keys like this:

type DerivedType = {
  name: string;
  mobile?: string;
}

Does there exist a less manual way of doing this without picking up the keys using Pick utility type?

I used Pick utility type to achieve this in the following way:

type DerivedType = Pick<ExistingType, 'name' | 'mobile'>

It works but it is very verbose, and if there are many keys in the original type then it becomes very tedious and unclean.

Shreenath
  • 51
  • 5
  • **All:** The goal here is to remove **the index signature**, so it's not just a case of "use `Omit`." :-) – T.J. Crowder May 26 '23 at 14:45
  • 1
    ... **but** it is a duplicate of https://stackoverflow.com/questions/51465182/how-to-remove-index-signature-using-mapped-types – T.J. Crowder May 26 '23 at 14:46

0 Answers0