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.