Reputation: 6582
Is it possible to use part of an interface as new interface in Typescript? for example I have interface below:
interface Mobile{
canCall: boolean;
haveScreen: boolean;
isItIOS: boolean;
brand: string;
}
Now I want to use just some of Mobile interface data, for example I only need :
interface phone{
canCall: boolean;
brand: string;
}
how Can I use Mobile interface data in phone interface?
Upvotes: 2
Views: 167
Reputation: 37918
You can use Pick util for this
Constructs a type by picking the set of properties K from T
interface Mobile {
canCall: boolean;
haveScreen: boolean;
isItIOS: boolean;
brand: string;
}
type Phone = Pick<Mobile, 'canCall' | 'brand'>;
Upvotes: 4