Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 627 Bytes

README.md

File metadata and controls

24 lines (19 loc) · 627 Bytes

PickProperties<Type, Value> constructs a type by picking all properties from type Type which values equal to Value

interface UserInformation {
  birthday: Date;
  email: string;
  id: string;
  name: string;
  happyBirthday: () => void;
  hello: () => void;
}

type UserActions = PickProperties<UserInformation, Function>;
//   ^? { happyBirthday: () => void; hello: () => void; }

Value can also be a union type

type UserFields = PickProperties<UserInformation, Date | Primitive>;
//   ^? { birthday: Date; email: string; id: string; name: string; }

TS Playground – https://tsplay.dev/wXO1LW