Create a new type based on another type except refine its properties to the ones picked.
Applicable React example:
// User Modelinterface User {id: number,first_name: string,last_name: string,phone: number,address: string}// User component to display user's full nameconst UserFullName = ({first_name, last_name}: Pick<User, 'first_name'|'last_name'>) => (<h4>{ first_name } { last_name }</h4>)
Create a mapped type using values of an union type as keys and values type set to the subsequent generic.
Applicable React example:
type Statuses = "failed" | "complete";interface Status {iconType: IconTypesiconColor: IconColors}const icons: Record<Statuses, Status> = {failed: {iconType: "warning",iconColor: "red"},complete: {iconType: "check",iconColor: "green"}};interface StatusProps {status: Statuses}const Status = ({status}: StatusProps) => <Icon {...icons[status]} />